Can't connect to database with PDO

I finally decided to take a look at PDO, and I can’t even connect to my database. This is my original connection (though I’ve changed the values, of course)…


$link = mysql_connect ("localhost" , "Money" , "XYZ") or die(mysql_error());
mysql_select_db ("db_horse", $link) or die(mysql_error());

And this is how I translated it for PDO…


try {
    $conn = new PDO('mysql:host=localhost;dbname=db_horse', $Money, $XYZ);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

But I get this error message:

ERROR: SQLSTATE[42000] [1044] Access denied for user ‘’@‘localhost’ to database ‘db_horse’

I have PHP version 5.3.6 on a Mac, using MAMP Pro.

Thanks.

The username and password must be strings, not variables.


<?php
try {
    $conn = new PDO('mysql:host=localhost;dbname=db_horse', "Money", "XYZ");
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

Or variables containing the correct strings.


$db_username = "Money";
$db_password = "XYZ";
// ...
    $conn = new PDO("...", $db_username, $db_password);

Wow, I thought those dollar signs looked odd. I copied it right from the tutorial!

Thanks.