Can't get PHP PDO to work

Hey fellas!

I recently reactivated my (Shared Hosting) DreamHost account, and I’m trying to develop a relatively simple PHP program that needs to retrieve data from a mysql database. However, I keep getting this error:

ERROR: SQLSTATE[HY000] [2002] Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

My code is as follows:

 $this->database = new PDO(
                "mysql:host=" . $host . ";dbname=" . $database,

I’ve used the values of $host, $dbUser, and $dbPassword to log in to myPHPAdmin, so I know they’re right. I’ve also double-checked the database name. Any idea what I’m doing wrong?

The error message you’re getting indicates to me that PHP is either not seeing a hostname, or is ignoring it for some reason. Are you certain $host is set correctly in this context? (Try printing it right before you try connecting or something.)

I’d probably change $host to $dbhost in case something trips that variable up later, too. Or maybe define the db stuff.

[php]define(“DBHOST”, “”);
define(“DBNAME”, “blah”);
// more defines…
$this->database = new PDO(‘mysql:host=’.DBHOST.’;dbname=’.DBNAME.’’, DBUSER, DBPASS);[/php]