Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP cant connect to MySQL on localhost

Status
Not open for further replies.

comboy

Instructor
May 23, 2003
226
Hi all,

I'm new to web development but I've set up apache 2.x MySQL 5.x and PHP5 on XP home.

When I use a phpinfo() script it shows up on the local host and seems that every thing is ok.

However when I try and connect to MySQL using the code below I just get a blank page with no warnings etc

Code:
<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'joeuser', 'pass')
   or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
mysql_select_db('testDB') or die('Could not select database');

// Performing SQL query
$query = 'SELECT * FROM test';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "\t<tr>\n";
   foreach ($line as $col_value) {
       echo "\t\t<td>$col_value</td>\n";
   }
   echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>

when configuring php I've done the following

1. created a new text file and copied the contents of php.ini-recommended to it and saved it as php.ini

2. added LoadModule php5_module "c:/php/php5apache2.dll" to the httpd.conf

3. added AddType application/x-httpd-php .php .html to the httpd.conf

4. added PHPIniDir "c:/php" to the httpd.conf

5. Added ;C:\php to the Windows systems PATH

Have I missed anything and any ideas why I'm just getting a blank page?


Any help greatly appreciated

Graham.
 
can you access mysql via the command line?
have you loaded the mysql library in the php.ini file (typically if not you would throw an error)
have you got error reporting and error display turned on in your php.ini file?

if you make any changes to your php.ini file, restart apache after saving it.
 
Hi guys

Thanks for the replies apologies for the lateness.
Yes jpadie I can connect to MySQL via cmd and enter data etc.
How do I set up the php.ini to report errors and load the MySQL libary do I take out the ; before extension?


Thanks again for the help.

Graham
 
yes. you take out the semi-colon.
then restart the web-server.

you may need to ensure that libmysql.dll is copied to you windows/system32 directory. personally i copy it to the php directory and ensure that this directory is in the windows path.
 
Thanks for that jpadie I'll try your suggestions. I've placed the directory into the windows path but I'll try copying the libmysql.dll into system32 and see if that helps.
I'll post back and let you know

Thanks again


Graham
 
Hi guys,

Just to let you know that I've sorted out the problem with php

I had to enter the extension directory into the php file uncomment the error reporting and mysql extension, this appears to have sorted the problem.


Cheers,


Graham.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top