Http://www.163ns.com/zixun/post/5295.html
This article summarizes the PHP development may often encounter some of the PHP connection to the MySQL database of some of the problems and solutions to share, there is a need for friends to refer to.
Question One
Today to install MySQL and PHP, all the installation is normal ([email protected]). But the "#2002无法连接" error occurs when connecting tests with phpMyAdmin, and the same problem is with other programs.
Check it out, PHP's MySQL extension is properly installed, MySQL service starts normally-that's odd. Again with Navicat connection, incredibly connected. There seems to be a problem with the communication between PHP and MySQL.
Baidu a bit, the problem was pulled out:
The mysql_connect () function database server (server) parameter is currently set to localhost, but can be accessed normally when it is changed to 127.0.0.1.
The system Hosts file did not provide a resolution of 127.0.0.1 to localhost.
Workaround (Take the Win7 system as an example): Find the C:\Windows\System32\drivers\etc\hosts file, default to read-only, you need to copy one to other paths such as desktop, open file (open with: Notepad), add at the end of file:
127.0.0.1 localhost
If it already exists, remove the "#" from its front.
Question Two
PHP scripts can run normally, such as phpinfo ().
As long as a "mysql_connect" function, there is no response, nor error.
such as $conn = mysql_connect ("127.0.0.1", "root", "xxxx") or Die ("MySQL database connection failed:". Mysql_error ());
Apache Log directory Error.log appears in
PHP warning:php startup:unable to load Dynamic library ' C:\\php\\ext\\php_mysql.dll '
Solutions
Copy "Libmysql.dll" to the Apache Bin directory. Then restart, observe the Error.log, if the error disappears, then congratulations.
Another: Online information also said to the "Libmysql.dll" "" Php_mysql.dll "copied to Windows/system32.
Question Three
Code to copy code as follows
[email protected]_connect ("localhost", "Sampadm", "secret");
The following code omits
?>
The following prompt appears at run time:
Fatal error:call to undefined function mysql_connect () in var/www/html/mytest.php
Workaround
In 1.php.ini
Extension_dir is set to the "D:\apache2\php\ext" absolute path, otherwise there will be an error in some environments.
Open the following two lines of feature extension
Extension=php_mysql.dll
Extension=php_mysqli.dll
2. Copy libmysql.dll (under PHP directory) and Php_mysql.dll (Php/ext directory) to C:\Windows\System32 directory (Libmysql.dll must be a PHP directory, such as my d: Libmysql.dll,php_mysql.dll in the \apache2\php directory is D:\apache2\php\ext)
3. Test,
1> Open the command line first
A) Click "Start" menu, "MySQL", "MySQL5 server", "MySQL Command line Client"
If this succeeds, MySQL security succeeds, the MySQL installation fails, please uninstall and reload
B) Enter the password
This step normally indicates that the password for the root account is correct. Failure is the wrong account password
2> Create a new file to the home directory and save it as testmysql.php, then enter http://localhost/testmysql.php (or http://localhost:81/testmysql.php) in the browser
If not, check to see if Apache has loaded the PHP and MySQL methods
Support for PHP5 in Apache add the following three lines to the httpd.conf file
Phpinidir "d:/ccopen/php5/"
LoadModule php5_module "D:/ccopen/php5/php5apache2_2.dll"
AddType application/x-httpd-php. php
Remove the following two lines of semicolons in the php.ini
Extension=php_mysql.dll
Extension=php_mysqli.dll
Copy Php_mysql.dll and Libmysql.dll to System32.
Re-starting Apache server
PHP is unable to connect MySQL problem solving method Summary