I'm using a slight variation on the PHP PDO Wrapper Class found here: http://www.imavex.com/php-pdo-wrapper-class/
This is the new constructor I'm using:
public function __construct($dsn, $user='', $passwd='') {
$options = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
try {
parent::__construct($dsn, $user, $passwd, $options);
} catch (PDOException $e) {
$this->error = $e->getMessage();
}
}
error is a private variable of this class, defined at the begin of the class, above the constructor.strong text
And when I use it like this
$database = new Database(
'mysql:host=' . $config['mysql_host'] . ';port=' . $config['mysql_port'] . ';dbname=' . $config['mysql_database'],
$config['mysql_username'],
$config['mysql_password']
);
It shows me this error: Creating default object from empty value, pointing to the database class file, at the line $this->error = $e->getMessage();.
The reason an exception is thrown is because I haven't set the mysql username and password yet, so don't worry about that. I'm trying to figure out why it gives this error and how to fix it.