views:

37

answers:

3

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_mysql.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)

A: 

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.

Skilldrick
thanks I'll definitely check that out for my next install. For this one I'd kind of like to fix this problem in the hopes of raising my understanding of how these technologies work together.
matthew_360
Fair enough. Sometimes it's useful to get more familiar with a technology before diving down into its innards though!
Skilldrick
okay, got me intrigued. Im gonna put it on my laptop now
matthew_360
@matthew_360 :)
Skilldrick
+1  A: 

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.

Chris Thompson
I turned my firewall off, and that didn't help. How do I change what port mySQL is using? And which port is php expecting it to use?
matthew_360
pretty sure you were right about something not being configured correctly in mySQL. I uninstalled it, and re-installed, and now it works! thanks for your help.
matthew_360
Maybe something to do with installation order? Anyway, glad it's sorted.
Skilldrick
@matthew_360 Great! Sorry I didn't get a chance to respond to your earlier comment but I'm glad you got it figured out!
Chris Thompson
A: 

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

Pascal MARTIN
that is interesting, and I am using windows 7. However, changing localhost to my IP didn't fix the problem (although, this might have been a problem later.)
matthew_360
OH ; too bad :-(
Pascal MARTIN