Friday, November 12, 2010

How I wasted 3 hours

My untold thanks to the many anonymous people who post on help boards. I spent 3 hours trying to get PHP to access MySQL database. Finally found out about something called an "error log" (herp), how to enable errors on my web page (derp), and finally that the problem wasn't that PHP couldn't talk to MySQL (although maybe some of the tinkering I did in the php.ini file did some good) but it was rather the following bad code:

$connection=mysql_connect($db_host, $db_username, $db_password);
if (!=$connection) {
die ("Error ".mysql_error());
}

Rather it should be have been:

$connection=mysql_connect($db_host, $db_username, $db_password);
if (!$connection) {
die ("Error ".mysql_error());
}

I feel stupid, for sure, but also incredibly happy that it's not a problem with talking to MySQL (especially since I'm programming in a virtual environment, Linux, running on top of my Mac OSX (herp derp)).

If anyone in the future ever has problems displaying PHP (and gets what seems like the page unwilling to render when some of it isn't parsing correctly), check the Apache (or web server) error log, FFS.

EDIT: Also, the problem could have been this:

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

If this happens, enter the following in the command line
  • cd /etc/apache2/conf.d
  • sudo touch fqdn
  • echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn
That should do the trick.

No comments: