Jump to content

Call To Undefinded Function mysql_connect

Recommended Posts

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

How do I solve this? Whats wrong with PHP5?[/quote]
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:

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

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 [b]php.ini-recommended[/b] 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:
[code]extension_dir = "./"[/code]
change this line to the following:
[code]extension_dir = "C:\php\ext"[/code]
What this line does is tells PHP where all your PHP extensions are located to.

[b]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[/b]

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 [b]libmysql.dll[/b] 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!
Link to comment
Share on other sites

  • 9 months later...
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.
Link to comment
Share on other sites


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.