Computing.Net > Forums > Web Development > Cannot connect to MySQL DB with PHP

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Cannot connect to MySQL DB with PHP

Reply to Message Icon

Name: genscripter
Date: May 6, 2009 at 11:47:00 Pacific
OS: Windows XP
CPU/Ram: 8 GB
Product: Dell / M6300
Subcategory: PHP
Comment:

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>



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: May 6, 2009 at 13:05:48 Pacific
Reply:

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


0

Response Number 2
Name: genscripter
Date: May 6, 2009 at 13:52:39 Pacific
Reply:

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>


0

Response Number 3
Name: genscripter
Date: May 6, 2009 at 14:51:38 Pacific
Reply:

It appears that I didn't have a library installed. Something like mysql.dll. I'll post more as I find out more info.


0

Response Number 4
Name: shutat
Date: May 6, 2009 at 15:21:33 Pacific
Reply:

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


0

Response Number 5
Name: Claude111
Date: August 3, 2009 at 13:10:00 Pacific
Reply:

"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.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Cannot connect to MySQL DB with PHP

Cannot connect to MySQL with PHP www.computing.net/answers/webdevel/cannot-connect-to-mysql-with-php/1668.html

PHP connection to MySQL www.computing.net/answers/webdevel/php-connection-to-mysql/235.html

cannot connect to mysql with php www.computing.net/answers/webdevel/cannot-connect-to-mysql-with-php/2968.html