Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/10/2012, 14:44
Avatar de asdmaster
asdmaster
 
Fecha de Ingreso: marzo-2010
Mensajes: 98
Antigüedad: 14 años, 1 mes
Puntos: 2
Donde esta el error ??? Singleton PDO

No logro entender que esta mal.

Código PHP:
class SPDO
{
    static 
$dbh;
    
    public function 
__construct()
    {
        try
        {
            
$dsn 'mysql:host=' HOST ';dbname=' DATABASE;
            
self::$dbh = new PDO($dsnUSERPASSWORD);
        }
        catch (
PDOException $e)
        {
            echo 
'Connection failed: ' $e->getMessage();
        }
    }

    public static function 
getInstance()
    {
        if (
self::$dbh == NULL)
        {
            
self::$dbh = new SPDO();
        }
        return 
self::$dbh;
    }

Código PHP:
class Model
{
    public 
$dbh;

    public function 
__construct()
    {
        
$this->dbh SPDO::getInstance();
        
$this->dbh->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
        
$this->dbh->setAttribute(PDO::ATTR_EMULATE_PREPARESFALSE);
    }

Cita:
(!) Fatal error: Call to undefined method SPDO::setAttribute()