MySQL Forums
Forum List  »  Newbie

Re: undefined function mysql_connect()
Posted by: Russell Dyer
Date: July 07, 2005 09:06PM

For some reason, your PHP engine does not have the MySQL client library installed. This commonly happens when a server is upgraded from PHP4 to PHP5. PHP4 included MySQL by default. However, PHP5 does not. To confirm this diagnosis, run a PHP script with a call to phpinfo(). The following code run through your web browser is all it needs to contain:

<?php
phpinfo();
?>

Running phpinfo() gives you a lot of information that can help diagnose problems. Look for a block labeled mysql in the results.

You need to edit (or create) the php.ini file on your server. Typically it's placed in the directory c:\windows, but it can be in various locations or even absent. If you cannot find it by running Windows' search tool, then it is likely that your PHP installation is running without one and just using default settings. Copy one of the sample php.ini files that came with your PHP distribution into c:\windows.

Once you have found or created a php.ini file, you need to find the section headed Windows Extensions. It should look like this:

;Windows Extensions

;extension=php_mssql.dll
;extension=php_msql.dll
extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_oci8.dll


In a .ini file, a line beginning with a semi-colon (;) is a comment and will not be parsed. In the snippet above, the mysql library is enabled (because its line does not begin with a semi-colon). Find the MySQL library that you want to enable and remove the semicolon from the beginning of that line. Then restart your web server for the change to take effect. Once this is done, you should now be able to run mysql functions. If you need to enable multiple modules, it would a good idea to enable them one at a time and to do some testing in between.

Russell Dyer

Author of "MySQL in a Nutshell" (O'Reilly 2005).

Options: ReplyQuote


Subject
Written By
Posted
Re: undefined function mysql_connect()
July 07, 2005 09:06PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.