PHP & IIS: Addressing “Fatal error: Call to undefined function mysql_connect()”
I’ve been working on a project that is hosted in a Windows environment, but requires PHP and MySQL. My development and test environments are using the LAMP stack with which I’ve never had any trouble getting the two modules to play nicely. Going into the project, I knew that it was a little more of a headache to setup PHP and MySQL with an IIS webserver, but I also knew it could be done. I installed PHP and MySQL and also made the appropriate changes to the PHP.ini file. Unfortunately, PHP was still not able to interface with the database and I received this error:
Fatal error: Call to undefined function mysql_connect()
If you’ve suffered from this problem, here are a couple of things to check in a roughly appropriate order.
- Make sure that you have the correct parameters in your PHP code. Often times in development, you’ll be connecting to a development database or a test database and forget to modify the script when you push to production.
- Verify that php_mysql.dll is located in your PHP installation directory and that you uncomment the line in PHP.ini that contains extension=php_mysql.dll.
- Lastly, make sure that you’ve setup your Environmental Variables in Windows. To do this, Start | Settings | Control Panel | System. Click on the ‘Advanced’ tab, then click the ‘Environmental Variables’ button. In the ‘System Variables’ frame, click on ‘New’ and then give the variable name ‘PHPRC’ and give the value to the root directory of your PHP installation (such as C:\PHP). Restart the machine (not just the webserver).
I failed to perform Step 3 in my initial configuration; however, after I restarted the server everything worked exactly as it should. If you’ve experienced this error, and none of the above help to address the problem, leave me comment - I’m interested to see any other erratic behavior that may occur in an IIS/PHP/MySQL environment.
Edit: May 22, 2008
Matt left a comment about a MySQL function freezing his machine that was running IIS6. Despite a few initial thoughts, I really wasn’t sure what had happened. After a short email exchange, he let me know what the problem was and how to fix it, so I’m including his response as another tip for this post:
- “It turns out that the IIS installer (.msi version) doesn’t put the proper PHP path in the mime type. It comes out reading like c:\php\PHP5~.dll which fails to run. I had to change it to the proper path c:\php\php5isapi.dll without the Windows truncation.
As for the corruption, I have no idea what happened. I had to re-install PHP5 and configure php.ini all over again to get my sites back up.”

21. May 2008 at 00:05
So I’ve been using mysql_connect() just fine under IIS6 until I froze my computer running a MySql function. After rebooting all my sites give me the call to undefined function error. Any reason? Corrupt file?