Just today friend XJB also encountered this problem, so wrote this note, the description of the problem and the resolution of the record.
Problem Description: Web-style, 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 option has been opened, and the test script is simple, with a mysql_conect function that reads:
Copy CodeThe code is as follows:
Ini:
Extension=php_mysql.dll
The test script test.php content is as follows:
text.php
if (!mysql_connect (Dbhost, dbuser,dbpwd))
{
echo "Connection failed!";
Exit
}
echo "Connection succeeded!t";
?>
Call http://localhost/test.php with the Web, perform normally, and show "Connection succeeded."
But the D:/php/php.exe test.php is called with a DOS command line, but the connection fails with the error message: Fatal error:undefined function mysql_connect ()
Obviously, in the DOS command line environment, the MySQL module is not called. method, still cannot be solved. The solution is not to be baffled. Later, I wrote a script to see how the PHP configuration differs in two environments:
test.php
Copy CodeThe code is as follows:
Echo Phpinfo ();
?>
A closer look at the PHP configuration information for the phpinfo () input in two environments has finally found the problem:
When the Web mode is called http://localhost/test.php, its Configuration File (php.ini) Path is displayed as C:windowsphp.ini.
When D:/php/php.exe test.php is called by the DOS command line method, its Configuration File (php.ini) Path is D:phpphp.ini.
In the c:windows and d:php directories, there is a php.ini file, php.ini in the d:php directory does not open the Extension=php_mysql.dll module. So will d:phpphp.ini delete, only keep c:windowsphp.ini, problem resolution.
Summary: When installing PHP under Windows, in order to avoid the configuration file confusion, the installation directory under the php.ini copy to the Windows directory, the original installation directory should be renamed or deleted php.ini files, in order to prevent the execution of different environments, find the configuration file inconsistent The situation occurs. The cause of the problem is generally very, very simple, but the process of finding and excluding the problem is rather annoying.
http://www.bkjia.com/PHPjc/322737.html www.bkjia.com true http://www.bkjia.com/PHPjc/322737.html techarticle just today friend XJB also encountered this problem, so wrote this note, the description of the problem and the resolution of the record. Problem Description: Web-style, can link MySQL, but in ...