Technical notes _php tips for solving PHP's inability to link to MySQL at the DOS command line

Source: Internet
Author: User
Tags install php phpinfo
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:

?
Echo Phpinfo ();
?>


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.
Related Article

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.