I installed Apache 2.2, PHP 5.2 and mySQL 5.0. Everything seemed to be going great, until I tried to open a connection from PHP to mySQL. I got the dreaded error.
Call to undefined function mysql_connect()
So, off I went looking for a solution. I checked Google, I read though about 50+ threads/posts on various websites. I checked Experts-Exchange, and read a bunch of posts there, and nothing.
I tired all the normal stuff:
- Put the php.ini file in the c:\winodows - Nope!
- Put the php.ini file in the c:\winodws\system32 - Nope!
- Put the libmysql.dll in the c:\winodws\system32 - Nope!
- Put all three files (php_mysql.dll, php_mysqli.dll, libmysql.dll) in the c:\winodws\system32 - Nope!
- I tired every combination of that. Also tired a whole bunch of stuff in the apache conf file (C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf) and still nothing.
Finally I decided to just nuke the PHP installation and start over. So I re-downloaded the latest PHP windows installer from the Official Website. THAT IS MY MISTAKE RIGHT THERE. The windows installer does not include all the extension files. If you are going to use the installer, also download the zip package which contains the \ext\ folder, with a slew of dll files that might come handy at some point.
If you are getting the php_mysql.dll, php_mysqli.dll, libmysql.dll files from another location, they might not be the proper version and you will have problems. Make sure your windows installer version and the zip package version are the same.
Then put in the php.ini put in the following statements to enable the extension:
Also copy the libmysql.dll file from the ZIP package and put it into the php root directory (default: c:\php)
After spending 4 hours trying to configure this whole mess I finally figured it out. It was very simple.
Method to the madness
If this doesn't work for you then I'm sorry. I can tell you how I managed to figure it out at least.
Lots of different searches in Google. There are ton of configurations possible - everything from different OS, to different versions of PHP and Apache. Therefore tons of solutions exist. You have to weed out the ones that don't apply to you.
If you are using the current build of Apache and PHP, then don't look at posts/threads that were created 3 years ago. Those steps won't apply to you anymore.
Another resource I used was the Apache Error log. It told me:
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\PHP\\ext\\php_mysql.dll' - The specified module could not be found.\r\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\PHP\\ext\\php_mysqli.dll' - The specified module could not be found.\r\n in Unknown on line 0
Thus I knew that Apache was having problems loading the dll files. I knew the files where there, and the permissions were correct, which led me to believe that I was using the wrong version or corrupt files.
Persistence pays off. No one will be able to give you a sure fire solution to your error because every system is different, so you'll just have to troubleshoot yourself.
Trust me, you learn a lot about the inner workings of these application that way.