PHP cannot connect MySQL problem solving method Summary _php Tutorial

Source: Internet
Author: User
Tags php and mysql apache log mysql command line
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 (php@iis7.5-fastcgi). 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

The code is as follows Copy Code
$link _id= @mysql_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

http://www.bkjia.com/PHPjc/632173.html www.bkjia.com true http://www.bkjia.com/PHPjc/632173.html techarticle 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 ...

  • 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.