Cannot connect to MySQL DB with PHP

Dell / M6300
May 6, 2009 at 11:47:00
Specs: Windows XP, 8 GB
I'm having trouble just verifying if I can connect to my MySQL db. I've tested all my permissions and verified that PHP works on my server. I can get the page to display "A" thru "C", but once it hits the mysql_connect method, it stops all echos and calculation. Any help would be greatly appreciated. :)

<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<TITLE>Test TEST</TITLE>
<META name="description" content="Test TEST.">
<META name="keywords" content="test, Dev">
</HEAD>
<BODY bgcolor="#FFFFFF">


<?php
echo 'I will try to connect to db<br/>';
$host = 'localhost';
echo 'A<br/>';
$user = 'buser2';
echo 'B<br/>';
$pass = '1234';
echo 'C<br/>';

$db = mysql_connect($host, $user, $pass);
echo 'D<br/>';
if (!db){die("Unable to connect to database".mysql_error());}
echo 'E<br/>';
echo '<br/>Test successful';
?> 


</BODY>
</HTML>


See More: Cannot connect to MySQL DB with PHP

Report •


#1
May 6, 2009 at 13:05:48
Do you have mysql installed? If not, you'll need to download and install it first.

If you have it installed, does buser2 have permission to connect to the data base from localhost? If not, you will need to "grant" access to buser2.

You might also want to add error_reporting(E_ALL); to the top of your php file. Hopefully, that will catch any errors that you've got.

Hope that helps

______________________
My work in progress. I hate JS. :P


Report •

#2
May 6, 2009 at 13:52:39
shutat,
thanks for the quick reply. In regards to your questions, I have MySQL installed because we have other databases functioning properly on the same server. I have a server manager (Webmin 1.470) that handles the password and username access. Would this application complete the "granting" process or is this a completely separate thing from setting up users for db's or tables?
I've added the error check, but it still stops at echo "C," without any error messages. Is this how it should be employed:

<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<TITLE>Test TEST</TITLE>
<META name="description" content="Test TEST.">
<META name="keywords" content="Test, Dev">
</HEAD>
<BODY bgcolor="#FFFFFF">


<?php
error_reporting(E_ALL);
echo 'I will try to connect to db<br/>';
$host = 'localhost';
echo 'A<br/>';
$user = 'buser2';
echo 'B<br/>';
$pass = '1234';
echo 'C<br/>';

$db = mysql_connect($host, $user, $pass);
echo 'D<br/>';
if (!db){die("Unable to connect to database".mysql_error());}
echo 'E<br/>';
echo '<br/>Test successful';
?> 


</BODY>
</HTML>


Report •

#3
May 6, 2009 at 14:51:38
It appears that I didn't have a library installed. Something like mysql.dll. I'll post more as I find out more info.

Report •

Related Solutions

#4
May 6, 2009 at 15:21:33
Is the server on Windows or *nix? If it's linux, I'm definitely not going to be much help with configuration issues. Hopefully, someone else will be able to help out in that case.

If it's Windows, do you have the mysql command line client installed? If so, use it to login using those credentials. If the user account is properly set up, then you'll be able to query the server once php is configured. I've never used webmin.

I'd forgotten all about the php.ini file, but that would keep you from using mysql too. Edit the php.ini file and look for extension=php_mysql.dll You will also need to verify that the extension path is set correctly to that of php. If you still have issues, then you *might* get away with copying libmysql.dll to the system32 folder.

error_reporting is mostly for php coding errors. I'm not sure if it would flag sql not existing.

Hope that helps.

______________________
My work in progress. I hate JS. :P


Report •

#5
August 3, 2009 at 13:10:00
"It appears that I didn't have a library installed. Something like mysql.dll. I'll post more as I find out more info".

Genscripter, please post more info on how you solved it, as it apears that I have the same problem !

Many thanks.


Report •


Ask Question