Ver Mensaje Individual
  #2 (permalink)  
Antiguo 12/02/2014, 10:14
Erick_MD9
 
Fecha de Ingreso: julio-2013
Ubicación: México
Mensajes: 361
Antigüedad: 10 años, 9 meses
Puntos: 55
Respuesta: problema clase abstract PDO no conecta

Hola, no veo por que defines la clase como abstract; se deben definir así sólo si tienes metodos abstractos y no veo ninguno.

te dejo un singleton para conecciones con pdo.
Espero te sirva saludos.

Código PHP:
Ver original
  1. class DbConn {
  2.  
  3.     private static $engine = 'mysql';
  4.     private static $host = 'localhost';
  5.     private static $usuario = 'xxxxxxxx';
  6.     private static $password = 'xxxxxxxxxx';
  7.     private static $base = 'xxxxxxxxxxx';
  8.     private static $CONFIG = array( PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'' );
  9.     private static $instance;
  10.  
  11.     /**
  12.      *
  13.      */
  14.     private function __construct() {
  15.     }
  16.  
  17.     private function __clone() {
  18.     }
  19.  
  20.     /**
  21.      * @return string
  22.      */
  23.     public function __toString() {
  24.         return 'Conección a Bd';
  25.     }
  26.  
  27.     /**
  28.      * @return PDO
  29.      */
  30.     public static function getInstance() {
  31.         if (!isset(self::$instance)) {
  32.             $conn = self::$engine
  33.                 . ':dbname=' . self::$base
  34.                 . ';host=' . self::$host;
  35.             try {
  36.                 $PDO            = new PDO($conn , self::$usuario , self::$password , self::$CONFIG);
  37.                 self::$instance = $PDO;
  38.             } catch (PDOException $e) {
  39.                 exit('Falló la conexión: ' . $e->getMessage());
  40.             }
  41.         }
  42.         return self::$instance;
  43.     }
  44. }
  45.  
  46. //USO
  47.  
  48. $PDO=DbConn::getInstance();