Pdo error: Error connecting: could not find driver

I am new to php and mysql. I am running Apache 2.2.25, PHP 5.4.22, and MySql 5.1.72 on Windows 7 64 bit.

This code generates the error: Error connecting: could not find driver

<?php

ini_set(‘display_errors’,1);
error_reporting(E_ALL);

try
{
$pdo = new PDO(‘mysql:host=localhost;dbname=my_contacts’,‘root’,‘password’);
}
catch (PDOException $e)
{
$output = 'Error connecting: ’ . $e->getMessage();
exit();
}

echo ‘Connected to MySql<br>’;

Obviously I need to install or configure something, but I’m to sure where to look.

Thanks for any insight or ideas on this!
Robin

It is helpful to put your code into php tags; they are not available on the quick reply but you have to go to the advanced reply section.

As you guessed you need to enable or install a MySQL driver; are you sure pdo is available to you?

I would check out the php manual

You can confirm pdo is available using:


// Is PDO installed?
if (!defined('PDO::ATTR_DRIVER_NAME')) {
echo 'PDO is unavailable<br/>';
}
elseif (defined('PDO::ATTR_DRIVER_NAME')) {
echo 'PDO is available<br/>';
}

Thanks!
I solved it, I found this line in the php.ini file and “uncommented” it. now pdo works!
;extension=php_pdo_mysql.dll