Advertisement
estevaorada

db.php

Oct 16th, 2020
2,433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2.  
  3. class Banco
  4. {
  5.     private static $dbNome = '';
  6.     private static $dbHost = '';
  7.     private static $dbUsuario = '';
  8.     private static $dbSenha = '';
  9.    
  10.     private static $cont = null;
  11.    
  12.     public function __construct()
  13.     {
  14.         die('A função Init nao é permitido!');
  15.     }
  16.    
  17.     public static function conectar()
  18.     {
  19.         if(null == self::$cont)
  20.         {
  21.             try
  22.             {
  23.                 self::$cont =  new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbNome, self::$dbUsuario, self::$dbSenha);
  24.             }
  25.             catch(PDOException $exception)
  26.             {
  27.                 die($exception->getMessage());
  28.             }
  29.         }
  30.         return self::$cont;
  31.     }
  32.    
  33.     public static function desconectar()
  34.     {
  35.         self::$cont = null;
  36.     }
  37. }
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement