You code is a mess, it's probably because you're so horny ...
connect() method - why is it there ?:
if ($db === NULL)
it should be:
if (self::$db === NULL)
self::$db = new $class();
So, if $class == __CLASS__ == db , you do self::$db = new db(); doesn't seem right.
You cannot use PDO to prepare an identifier, such as a table or column.
$db->prepare('SELECT * FROM :table WHERE id = :id')->execute(array('table' => 'test', 'id' => 1));
Must be:
$db->prepare('SELECT * FROM `test` WHERE id = :id')->execute(array('id' => 1));
Try the following:
class db extends PDO { private static $db = null; public static function singleton() { if (is_null(self::$db) === true) { self::$db = new PDO('mysql:dbname='.reg::get('db-name').';host='.reg::get('db-host'), reg::get('db-username'), reg::get('db-password')); } return self::$db; } }
Like this:
$result = db::singleton()->prepare('SELECT * FROM `test` WHERE id = :id')->execute(array('id' => 1)); var_dump($result);
source share