开发者

Having troubles configuring PHP to work with mySQL

I'm venturing out of the world of .NET and into the world of open-source. However, I've hit a few roadblocks while trying to get my development environment set up. And I'm kind of stuck on the most recent one.

I have installed: Apache 2.2, php 5.3.2, and mySQL 5.1.48 everything is working pretty much; apache is serving up PHP pages, and I'm able to create databases and tables in mySQL, however, I can't seem to get php to communicate correctly with mySQL. My php.ini has these lines un-commented:

extension=php_开发者_如何学Pythonmysql.dll
extension=php_mysqli.dll

However, I keep getting this error message:

Warning: mysqli_connect(): (HY000/2002): 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 C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\mysql_test.php on line 15

any help would be greatly appreciated.

(btw, the php code runs properly when I put it on my web host)


This is most likely a configuration problem with the MySql server. It sounds like it either isn't listening on the correct port or something else is going on with the connection. You have the extensions loaded correctly because PHP is able to find the mysql functions. I would make sure you don't have a firewall blocking any of the requisite ports (actually, just try turning off your firewall and see what happens...just don't forget to turn it back on ;-) ). Also make sure if you are following a tutorial you didn't deviate from the MySQL setup instructions at all. If those don't work, post an update and we can try again.


This looks like bug #45150 : MySQL functions cannot be used with 5.3.x on Vista when using "localhost" -- I've had this problem once, and it took me some time to figure out what was causing it...

If you are working with Windows Vista (and possibly seven ?), and trying to connect to MySQL using "localhost" as host, try to replace that by the corresponding IP address : "127.0.0.1"


Or try to edit the hosts file, and to un-comment the line that corresponds to localhost in IPv4 :

127.0.0.1       localhost

(Remove the # at the beginning of the line)

Or to comment the line that corresponds to localhost in IPv6 :

#::1        localhost

(Add a # at the beginning of the line)


And here's an interesting article about that : PHP 5.3 and MySQL connectivity problem


Use XAMPP - it'll remove any headaches like this for local development.

XAMPP is a very easy to install Apache Distribution for Linux, Solaris, Windows and Mac OS X. The package includes the Apache web server, MySQL, PHP, Perl, a FTP server and phpMyAdmin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜