Advertisement
Guest User

connect class

a guest
Jan 15th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2. class connect
  3. {
  4.     protected $username;
  5.     protected $password;
  6.     protected $dbname;
  7.     protected $host;
  8.     public $pdoo;
  9.     function __construct()
  10.     {
  11.         $this->username = 'root';
  12.         $this->password = '';
  13.         $this->dbname = 'blog';
  14.         $this->host = 'localhost';
  15.         $this->connectToDb($this->username, $this->password, $this->host, $this->dbname);
  16.     }
  17.     protected function connectToDb($username, $password , $host, $dbname){
  18.         try {
  19.         $pdo = new PDO('mysql:host=' .$host .';dbname=' .$dbname, $username, $password);
  20.         $pdo->setAttribute(PDO::ATTR_ERRMODE , PDO::ERRMODE_EXCEPTION);
  21.         $this->pdoo = $pdo;
  22.         } catch (PDOException $e) {
  23.         echo $e->getMessage();
  24.             }
  25.     }
  26. }
  27.  
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement