Technical note To resolve PHP's inability to link MySQL under DOS command line _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.