PHP wont connect to MySQL

Hi I just installed mysql 5.5 on my win7 pc, i use IIS7 as my server, and i have had PHP 5.3.3 installed for several months

In a simple PHP script to connect to mysql i get a PHP error.

PHP Fatal error:  Call to undefined function mysql_connect() in C:\\inetpub\\wwwroot\\firstsql.php on line 8

It seems as though php does not recognize the mysql function call from this code:

$link = mysql_connect("localhost", "root", "password");

I have searched through many forums and threads from people with similar problems but cant seem to find a solution.
Here is what I have tried so far:

  • Uncommented mysql line in php.ini
  • Taken a copy of libmysql.dll placing it in my PHP directory as well as my sys32 directory
  • Taken a copy of php_mysql.dll from PHP/ext and putting it in my sys32 dir
  • Restarting IIS multiple times
  • both my PHP dir and mysql/bin dir are in my PATH variable

I am not sure what else to try,
Thanks in advance for any help

No, neither mysql or mysqli are listed in the array.

In what directories are those programs installed? For some reason Win7 can behave oddly if you install them in the program files folder (or program files (x68) for that matter)
Also, do you have a firewall running? If so, does it work if you disable the firewall?
Note that windows 7 runs a firewall by default if I’m not mistaken. Also take a look at that one.

Thank you for the prompt response!

PHP is in C:\PHP5
Mysql is in C:\Program Files\MySQl\MySQL server 5.5
Where would you recommend moving it to?

My Win7 firewall is off but I have a 3rd party firewall that I will check to make sure there is an exception to.
I do remember checking a “create exception in firewall” box during mysql configuration though.

mysql.exe already has a full permission in my firewall

From what I read that should be okay.
Are you sure you modified the correct php.ini ?
Use phpinfo() to see which php.ini php uses.

Phpinfo() has two results regarding php.ini (i’m not sure which one you want)

Configuration File (php.ini) Path--	C:\\Windows
Loaded Configuration File--	C:\\php5\\php.ini

So you uncommented ;extension=php_mysql.dll in C:\php5\php.ini and restarted IIS after you did that?

If so, I’m at the loss where the problem may be.

There is a tutorial on how to install PHP and MySQL on win7 with IIS here.
Maybe you see something in there that makes clear what’s going wrong.

Yes I did uncomment that line already… and I have already taken a look at that tutorial and many similar to it.

Thanks for the help though

It’s the “Loaded Configuration File” that you need to edit.

What port have you got MySQL set to use, try:

$link = mysql_connect("localhost:xxxx", "root", "password");

where xxxx is the relevant port number

I tried using the port number but it still did not work.
I think that the problem may lie in php not recognized the function as opposed to the SQL syntax being wrong.
However I am up to try anything at this point.

echo 'The following PHP extensions are loaded on this server';
echo '<pre>';
echo '</pre>';

Do you get an entry for either mysql or mysqli in the output from that?

I don’t think if its an issue of MySQL not running, I bet the issue is MySQL library is not loaded, as its a fatal error of undefined function.

Alright so how would i load the MySQL Library, specifically?

Thanks for the help

Normally removing the ; in ;extension=php_mysql.dll in php.ini should do it.
Is the extension path set correctly in php.ini and does php_mysql.dll exist within that path?

My extension dir was not set in the php.ini file, but i fixed that.
Unfortunately it still does not work. However i noticed an include path that was just above the ext path, commented out and empty, could that have anything to do with it?

Also looking at the extensions, the details for the extensions show that my php_mysql.dll is listed as version whereas the rest of the extensions are 5.3.0.
This is most likely because I downloaded the file off of the internet when I found that it was missing.
However, I cannot find a newer version. If somebody can, please provide me with a link.

Well… problem solved. I went to and downloaded the latest zip, took the php_mysql.dll file and placed it in my ext folder.

Thank you all for the help, couldn’t have done it myself.

P.S. Not sure how to mark as solved

You can’t. We leave threads open here on SitePoint so you can come back to it later might you have additional questions.

Glad you got it working btw! :slight_smile: