Jump to content


Call To Undefinded Function mysql_connect

  • Please log in to reply
1 reply to this topic

#1 wildteen88

  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 08 June 2006 - 09:20 PM

Why do I get the call to undefined function error message when connecting to mysql?

How do I solve this? Whats wrong with PHP5?

If you have PHP5 and MySQL installed on Windows you may find that when you goto connect to mysql you'll get an error message like the following:

Fatal error: Call to undefined function mysql_connect() in [path of script here] on line [line number here]

Now this error may come as a suprise for some people that have migrated from PHP4 to PHP5 and immediately think PHP5 is broken. This is not the case. In actual fact there has been a license change between PHP and MySQL. PHP no longer embeds MySQL support into PHP as of PHP5. Instead what you need to do is simply enable the mysql extension. Once you've done that you'll be able to use any of the mysql functions within PHP.

Okay first locate your php.ini file which is most probably located in either the windows folder (C:\WINDOWS), the system folder (C:\WINDOWS\SYSTEM32), or in your php folder. If it isn't in any of those folders simply do a quick search for it, if windows still cannot find it chances are you haven't created it yet. To do so simply goto your php installation folder (C:\php, defualt path) and find a file called php.ini-recommended now copy this to the Windows folder and rename it to just php.ini.

Once you have found your php.ini file, open it and find the following line:
extension_dir = "./"
change this line to the following:
extension_dir = "C:\php\ext"
What this line does is tells PHP where all your PHP extensions are located to.

NOTE: Change C:\PHP to the actuall path of your PHP folder if it is not located in the root of the hard drive, I used this as by defualt PHP is extracted/installed there

Now scroll down abit further and find the following line:
remove the semi-colon from infront of that line to enable the mysql extension.

Once you have done that save your php.ini and restart your server. When you goto use mysql_connect() again you shouldn't get any errors.

If you do get an error when you restart your server or use the mysql_connect function then make sure you have configured the path of the php extension folder and that you have successfully restarted the sercer correctly. Also make sure you have copied a file called libmysql.dll to the windows folder too. Once you have copied the file restart your sever again. This should now enable mysql support.

If you get no errors when you connect to mysql through php then you have successfully enabled the mysql extension!

I hope this has solved your problem with connecting to mysql with PHP5.

Also this FAQ can be used to enable mssql, msql and other database extensions too!

#2 akitchin

  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 05 April 2007 - 09:35 AM

it should be noted that ALL MySQL files from old installs must be removed from everywhere throughout the system - the most likely place this will jam you up is in the windows root, windows/system, or windows/system32.

once you've made sure those are all gotten rid of, setting the PHP root directory in your PATH environment should confine any issues you have to files within your PHP root directory.  this greatly reduces the number of possible issues it can be.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users