Advertisement
xlujiax

Conexion

Dec 3rd, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Description of Conexion
  4.  *
  5.  * @author Docente
  6.  */
  7. class Conexion {
  8.             // Implementación de Singleton
  9.     private static $instancia = null;
  10.     public function __construct()
  11.     {
  12.         try {
  13.             self::$instancia = new PDO('mysql:host=localhost;dbname=limapass','root', 'xlujiax147');
  14.             self::$instancia->exec("SET CHARACTER SET utf8");
  15.         } catch (PDOException $e) {
  16.             print "Error!: " . $e->getMessage();
  17.             die();
  18.         }          
  19.     }
  20.     public static function singleton()
  21.     {
  22.         if (!isset(self::$instancia)) {
  23.             $miclase = __CLASS__;
  24.             self::$instancia = new $miclase;
  25.         }
  26.         return self::$instancia;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement