Home >Backend Development >PHP Tutorial >undefined function mysql_connect_PHP tutorial
undefined function mysql tutorial_connect
When installing the php tutorial under windows, in order to avoid configuration file confusion, after copying the php.ini in the installation directory to the windows directory, the php.ini file in the original installation directory should be renamed or deleted to avoid confusion in different environments. When executing, the search configuration file is inconsistent
fatal error: undefined function mysql_connect()
Environment: windows 2003, php 5.2.0, mysql 5.0, apache 2.0
In php.ini, the module option of php_mysql.dll has been turned on; the test script is also very simple, just a mysql_conect function, the content is as follows:
Copy the code. The code is as follows:
php.ini:
extension=php_mysql.dll
The content of the test script test.php is as follows:
text.php
if ( !mysql_connect(dbhost, dbuser,dbpwd) )
{
echo "Connection failed!";
exit;
}
echo "Connection successful!t";
?>
Use the web method to call http://localhost/test.php, the execution is normal, and "Connection successful" is displayed.
But using the dos command line to call d:/php/php.exe test.php shows that the connection failed. The error message is: fatal error: undefined function mysql_connect()
Obviously, in the dos command command line environment, the mysql module is not called. I tried all the methods, but still couldn’t solve it. I was puzzled. Later, I wrote a script to see the difference between the php configuration in the two environments:
test.php
Copy the code. The code is as follows:
echo phpinfo();
?>
Carefully check the php configuration information input by phpinfo() in the two environments, and finally found the problem:
When calling http://localhost/test.php in web mode, its configuration file (php.ini) path is displayed as c:windowsphp.ini.
When calling dos command command line mode d:/php/php.exe test.php, its configuration file (php.ini) path is d:phpphp.ini.
In the c:windows and d:php directories, there is a php.ini file. The php.ini in the d:php directory does not open the extension=php_mysql.dll module. So I deleted d:phpphp.ini and kept only c:windowsphp.ini, and the problem was solved.