Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/01/2013, 03:43
Bugger
 
Fecha de Ingreso: septiembre-2010
Ubicación: /home/
Mensajes: 103
Antigüedad: 13 años, 7 meses
Puntos: 17
Fatal error: Call to a member function prepare() on a non-object

Hola a tod@s

tengo el siguiente error - la classe que tengo es la siguiente:
Código PHP:
class sql {
    
    public static 
$db false;
    private 
$database_type 'mysql';
    private 
$database_host 'host';
    private 
$database_user 'user';
    private 
$database_pass 'user';
    private 
$database_db 'bd';

    function 
__construct()
    {
        if (
self::$db === false) {
            
$this->connect();
        }
    }

    private function 
connect()
    {
        
$dsn $this->database_type.":host=" $this->database_host.";dbname=" .$this->database_db;     
        
        try {
            
            
self::$db = new PDO($dsn$this->database_user$this->database_pass);
            
self::$db->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
            global 
$db;
            
        } catch (
PDOException $e) { 
            
            echo 
$e->getMessage();
            
        }
    }

y al llarmarla me da el error: Fatal error: Call to a member function prepare() on a non-object
Código PHP:
include_once("lib/conexion.php");
$q sql::$db->prepare("SELECT * FROM usuarios WHERE usuario = ?");
$q->execute( array( "nombre_usuario" ) ); 
while( 
$r $q->fetch) ){
    echo 
$r['id'];

Saludos y gracias