PDO ile bağlantı Sorunu

0 Cevap php

It's the first time i'm using PDO just for testing purpose. But a strange error occurred and googling it, it seems to be weird.

İşte benim veritabanı test sınıfı bulunuyor

class db extends PDO
{
    # Our instance.
    private static $db = NULL;

    # Calling the connector.
    public static function connect()
    {
        if (self::$db === NULL)
        {
            $class = __CLASS__;
            self::$db = new $class();
        }
        return self::$db;
    }

    # Connector.
    public function __construct() 
    { 
        $dns = 'mysql:dbname='.reg::get('db-name').';host='.reg::get('db-host');
        self::$db = new PDO($dns, reg::get('db-username'), reg::get('db-password'));
        reg::delete('db-password');
    }

    # Quick reporting
    public function reportError($array)
    {
        if ($this->db != NULL) { echo 'Myself getting horny'; } // Just for testing, i'm not getting horny because of a mysql database connection!
    }

}

Sonra aşağıdaki kodu çalıştırarak:

$db = new db();
$row = $db->prepare('SELECT * FROM test WHERE id = :id')->execute(array('id' => 1));
echo $row['value'];

Bana aşağıdaki hata gösterir:

Warning: PDO::prepare() [pdo.prepare]: SQLSTATE[00000]: No error: PDO constructor was not called in myfile.php on line 39

Hat 39 olarak göz önüne alındığında,

$row = $db->prepare('SELECT * FROM test WHERE id = :id')->execute(array('id' => 1));

0 Cevap