Did you enable the driver in the PHP.INI file?
In your PHP.INI search for extension=php_pdo.dll
and extension=php_pdo_mysql.dll
and remove the ;
in front of them. Save the file and restart the XAMPP-server.
Edit
I haven't had the opportunity to run it my self, not on my dev machine today, but you can try running this code in a new script to see if you get some more details on the error. I have set it up for throwing and catching errors, as well as dumping the phpinfo()
page to see if PDO is enabled and MySQL drivers are showing up.
<?php
class DBTest
{
private $dbname;
private $host;
private $port;
private $username;
private $password;
private $driver;
private $db;
public __construct($username, $password, $dbname = "", $host = "127.0.0.1", $port = 3306, $driver = "mysql")
{
$this->username = $username;
$this->password = $password;
$this->dbname = $dbname;
$this->host = $host;
$this->port = $port;
$this->driver = $driver;
}
private function getDSN()
{
return sprintf("%s:host=%s;dbname=%s;port=%d", $this->driver, $this->host, $this->dbname, $this->port);
}
private function connect()
{
try
{
$this->db = new PDO($this->getDSN(), $this->username, $this->password);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
return false;
}
return true;
}
public function getRealised()
{
if($this->db == null)
{
return false;
}
$sql = "SELECT * FROM realised";
try
{
$query = $this->db->prepare($sql);
$query->execute();
while($row = $query->fetch(PDO::FETCH_ASSOC))
{
print_r($row);
}
}
catch(PDO_Exception $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
return false;
}
return true;
}
}
$dbtest = new DBTest("root", "", "new_schema", "127.0.0.1", 3308, "mysql");
print("Created object");
if($dbtest->connect())
{
echo "Connected to DB";
}
if($dbtest->getRealised())
{
echo "Database queried";
}
phpinfo();