tags:

views:

58

answers:

1

I have a PHP site with a mySQL database that I'm working on. I'm running Apache, PHP, and mySQL on my development machine, and my code all works just fine. A week ago, I uploaded my code and database to my organization's web host (it's a non-profit group, so the host is not a dedicated in-house server, but rented space.) At that point, the code worked perfectly on the host site.

I added a few new pages this past week, so uploaded them today and went to test. And lo and behold, my code (existing code, not the new stuff) returns a database connection error.

The host company insists that the issue is on my end. How is that possible, if the code was working perfectly just last week and no changes have been made to the existing code? It seems to me the only possible explanation is that there was a change in the host's environment.

I'm pretty new to PHP, so I'm hoping someone can help me out here and explain whether it is possible or whether the host company's tech support is clueless.

A: 

Check your php error_log file. The database error will probably be listed there.

arnorhs
error_log shows the following error: "PHP Warning: mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /hermes/web06/b2247/pow.pcbadmin/htdocs/webTests/loginForm.php on line 9 " where line 9 is the line quoted in my comment to Samir above.
EmmyS
@EmmyS This sounds like the mysql server is not running. Check that your DB_HOST constant is set correctly. If you have shell access, check that you can connect to the db using CLI.
Rob Apodaca
Either mysql is not running or you have the wrong host name. @Rob is right, try echoing out the contents of the DB_HOST constant...
arnorhs
The DB_HOST is set by me in an include file. How will echoing the content help? The issue is whether the constant that I'm using matches what the hostname actually is, and as of a week ago it did.
EmmyS
As for the mySQL server not running: my access to the server is limited to a web interface called mySQLAdmin. But I am able to get at the database via that interface, so I'm assuming the server must be running.
EmmyS
yes, well, mysql might not be running on that particular host. Maybe the phpmyadmin interface is set up to connect to a remote mysql host. Echoing the DB_HOST where you're connecting will clearly print out which host you are connecting to. Sometimes it's a good way to realize some obvious mistake that you make - at least I make obvious mistakes all the time, and I consider myself pretty seasoned, so why shouldn't everybody else?
arnorhs
Thank you, @arnorhs. That was indeed the issue. The mySQLAdmin interface apparently does connect to a different host than the hosting company told me to use for actual connections. The host I was supposed to use was down. Kind of ticks me off that they insisted the issue was on my end, when it was their server that was down.
EmmyS
Yes, that's a hosting company for you :-) For some reason, the most obvious problems are always the hardest ones to solve...
arnorhs
Voting for this answer, even though the actual answer came in one of the comments further down (by same poster.)
EmmyS
Glad I could help :-)
arnorhs