Just today friend XJB also encountered this problem, so wrote this note, the description of the problem and the resolution record.
Problem Description: Web way, you can link MySQL, but at the command line, but prompted:
Fatal error:undefined function mysql_connect ()
Environment: Windows 2003, PHP 5.2.0, MYSQL 5.0, Apache 2.0
In PHP.ini, the Php_mysql.dll module options have been opened; The test script is also simple, with a mysql_conect function that reads as follows:
Copy Code code as follows:
Ini:
Extension=php_mysql.dll
The contents of the test script test.php are as follows:
text.php
?
if (!mysql_connect (Dbhost, dbuser,dbpwd))
{
echo "Connection failed!";
Exit
}
echo "Connected successfully!t";
?>
Invoke http://localhost/test.php in the Web, performing correctly, and displaying "successful connection".
But the call to D:/php/php.exe test.php in the DOS command line shows that the connection failed with the error message: Fatal error:undefined function mysql_connect ()
Obviously, the MySQL module is not invoked in the DOS command line environment. Method is exhausted and still cannot be solved. Puzzled by the solution. Later, I wrote a script to see what the configuration of PHP is, and what's different in two environments:
test.php
Copy Code code as follows:
With a closer look at the PHP configuration information that phpinfo () entered in both environments, the problem is finally found:
When the Web method is http://localhost/test.php, its Configuration File (php.ini) Path is displayed as C:windowsphp.ini.
DOS Command command-line D:/php/php.exe test.php call, its Configuration File (php.ini) Path is D:phpphp.ini.
In the c:windows and d:php directories, a php.ini file exists, and php.ini in the d:php directory does not open the Extension=php_mysql.dll module. So will d:phpphp.ini delete, only retain c:windowsphp.ini, problem solving.
Summary: When you install PHP under Windows, to avoid configuration file clutter, after you copy the php.ini from the installation directory to the Windows directory, you should rename or remove the php.ini file from the original installation directory to avoid the need to find the profile inconsistencies when executing in different environments The situation occurred. The cause of the problem is generally very, very simple, but the process of finding and eliminating problems is rather annoying.