Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2. class Database {
  3.  
  4.     public $dbh;   // handle of the db connexion
  5.  
  6.     protected $dbhost;
  7.     protected $dbuser;
  8.     protected $dbpass;
  9.     protected $dbname;
  10.  
  11.     public function __construct ($dbhost, $dbuser,$dbpass,$dbname) {
  12.  
  13.         $this->dbhost = $dbhost;
  14.         $this->dbuser = $dbuser;
  15.         $this->dbpass = $dbpass;
  16.         $this->dbname = $dbname;
  17.  
  18.         try {
  19.             $this->dbh = new PDO("mysql:host=$this->dbhost;dbname=$this->dbname", $this->dbuser, $this->dbpass);
  20.             /*$this->dbh->exec("SET CHARACTER SET utf8");*/
  21.         } catch(PDOException $error) {
  22.             echo $error->getMessage();
  23.  
  24.         }
  25.     }
  26.  
  27.     public function getPdo(){
  28.         return $this->dbh;
  29.     }
  30.  
  31.     public function __destruct() {
  32.         $this->dbh = NULL;
  33.     }
  34. }
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement