Call to undefined function mysql_connect() solution and PHP Fatal error: Call to undefined function mysql_connect() solution

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.

Solution 

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:

extension=php_mysql.dll
extension=php_mysqli.dll

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. 

Great job

hi I am so frustrated with this fatal error that i reinstalled PHP like 100 times but followed your instructions.... BINGO... right on target worked like a charm great job my friend Ajit

BIG THX!

I tried hard to solve this problem too and now it's worked thanks to this solution.... BIG THX!

BIG THX!

I tried hard to solve this problem too and now it's worked thanks to this solution .... BIG THX!

Thanks a lot for your help.

Thanks a lot for your help. This worked for me with PHP 5.2.6, Apache 2.0.63 and MySQL 5.0

Thanks for posting this......I tried them all until getting here

thanks for taking the time to posting your findings.... I went through several until I reached this one (and it worked) so much for a productive afternoon...(except trying and trying until it all 3 apps worked together...) thanks again

Thanks Alot

I have jst downloaded the zip and jst placed the ext folder in PHP Dir,its working fine,thanks alot for your hint.thanks budy-

BIG THANX

2 u

got me there!

i tried every combination much like you, till running across this page.. however, i still needed to copy the libmysql.dll to c:\windows\system32 to get it to work... the great thing you page made me realize was to stop using the copy i had gotten from another site and get the one from the php zip file... that was the big fix for me on Vista Home Pro SP1 + PHP 5.2.6 + (fixed it for Apache 2.2.9 and for IIS 7)

Post new comment

The content of this field is kept private and will not be shown publicly.