Handling PDO:_construct error on XAMPP

Drupal 7 now uses php data objects (PDO). The configuration file sites/default/settings.php now has lots of fanciness to support the variety of ways that it's possible to connect to a variety of databases.

If you're on XAMPP and you get a PDO:_construct error, I'll bet it's the unix socket. Here's the fix. Locate the section that specifies your database, username, and password, and add a 'unix_socket' line like below.


$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'database_name',
'username' => 'database_username',
'password' => 'database_user_password',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
'unix_socket' => '/opt/lampp/var/mysql/mysql.sock',
),
),
);

According to the D7 issue queue on drupal.org, Drupal is smart enough to ignore port and other stuff when it sees the unix_socket switch.

Cool, huh?