Advertisement
JoanMarcos

Untitled

Sep 25th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. <?php
  2.  
  3.     class Conexao {
  4.         private $usuario;
  5.         private $senha;
  6.         private $banco;
  7.         private $servidor;
  8.         private static $PDO;
  9.  
  10.         public function __construct()
  11.         {
  12.             $this->servidor = 'localhost';
  13.             $this->banco = 'SubArtigo';
  14.             $this->usuario = 'root';
  15.             $this->senha = 'joan1013';
  16.         }
  17.  
  18.         public function Conectar()
  19.         {
  20.             try {
  21.                 if (is_null(self::$PDO)) {
  22.                     return self::$PDO = new PDO("MYSQL:host=".$this->servidor.";dbname=".$this->banco, $this->usuario, $this->senha);
  23.                 }
  24.                 return self::$PDO;
  25.             } catch(PDOException $ex) {
  26.                 return print "Error!: " . $ex->getMessage() . "<br/>";
  27.             }
  28.         }
  29.  
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement