PHP cannot connect to database mysql_connect () Error

Source: Internet
Author: User

Install and configure Wamp, Apache 2.2.15 32-bit, php5.3.2 32-bit, and mysql5.5.2 64-bit on win7 64-bit. What is depressing is that all tests are OK, but they cannot connect to the database. At first they thought it was a time zone problem, so they modified PHP. INI data. timezone = PRC, the problem persists, and I found a post on the Internet that is the same as my problem. According to the method, the problem is indeed true, and the hosts has been modified for anti-Photoshop verification. The network is really a good thing!

Text from http://blog.sina.com.cn/s/blog_4ab014680100h59k.html

 

Warning: mysql_connect () [function. mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via TCP: // localhost: 3306) in E: /Apache/www/MySQL. PHP on line 20 warning: mysql_connect () [function. mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in E:/Apache/www/MySQL. PHP on line 20
Fatal error: Maximum execution time of 60 seconds exceeded in E:/Apache/www/MySQL. php on line 20

Recently, PHP was used in Windows 7 and encountered a very difficult problem. When phpMyAdmin was used to manage the MySQL database, an unknown error occurred and the database could not be connected for a long time, even if you use setup to configure phpMyAdmin, it cannot be loaded normally. However, it is strange that you can connect to it using mysqladministrator GUI tools. The problem is the same. I checked a lot of information for a long time to understand the problem? I hope to help you solve this problem today!

The solution is as follows:

First, check whether port 3306 is occupied. But if mysqladministrator GUI tools can manage the MySQL database, it should not be a port problem. Then, check whether the problem is caused by localhost. The result is in C: in the/Windows/system32/Drivers/etc/hosts file, localhost is not defined by default. #127.0.0.1 localhost is commented out, so remove, run again, OK! Everything is normal, and phpMyAdmin can be used normally.

 

I hope that friends who are confused about this problem can bring you the gospel of solution! We also hope to share our learning progress with you.

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.