Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2007, 09:45 AM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Connecting to PHP

I'm trying to get a simple connetion to mysql database using php running on localhost using an apache server but can't seem to get connected..i have all th necessary .dll files included in the php.ini file but i still can't connect nor is there a section in the phpinfo().php file like the section indicating that apache is set up, but there are a few references mentioned to the mysql directory. Is there something else i need to set up.

've 2 different examples of trying to connect

PHP Code:
<?php
$mysqli = new mysqli("localhost","root","Munster123");

if (mysqli_connect_errno())
{
    printf("Connect Failed: %s\n", mysqli_connect_error());
    exit();
}else{
printf("Host Information: %sn", mysqli_get_host_info($mysqli));
}
?>

returns an error
Fatal error: Class 'mysqli' not found in C:\Apache2\htdocs\testing.php on line 2


AND
PHP Code:
<?php
$link = mysql_connect('localhost', 'root', 'Munster123');
if (!$link) {echo 'Connected successfully';
}
else{
die('Could not connect: ' . mysql_error());}
mysql_close($link);
?>

returns an error
Fatal error: Call to undefined function mysql_connect() in C:\Apache2\htdocs\testing2.php on line 2

 
Old February 8th, 2007, 11:35 AM
Authorized User
 
Join Date: Nov 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mark jonas
Default

could be wrong with this as i am newish to mysql commands and so on but this is how i do it

$hostname = "localhost"; (Please bare in mine sometimes even using localhost wont work so do try with the ip address as well)

$database = "name of database";
$username = "username";
$password = "password";
$connect = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);

mysql_select_db($database, $connect) or die(mysql_error());

to me it doesnt look like your connected to the database (again could be wrong as i am new to this)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting to oracle from PHP paragajoshi PHP Databases 2 November 16th, 2011 05:26 PM
Connecting mysql to php?? Manu Sharma BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 3 March 5th, 2007 01:40 AM
Connecting To MySQL from PHP AlisP2P MySQL 1 January 4th, 2006 02:27 AM
Connecting to Oracle with PHP atcs2152 PHP Databases 0 December 16th, 2005 08:57 AM
connecting to mysql using Php webmoron BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 6 August 24th, 2004 04:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.