Advertisement
Guest User

Untitled

a guest
Nov 15th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. <?php
  2.     class Database
  3.     {
  4.         private $host="localhost";
  5.         private $username="root";
  6.         private $password="";
  7.         private $db_name="works";
  8.         public $connect;
  9.         public function dbConnection()
  10.         {
  11.             $this->connect=null;
  12.             try
  13.             {
  14.                 $this->connect=new PDO("mysql:host=".$this->host.";dbname=".$this->db_name,$this->username,$this->password);
  15.                 $this->connect->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  16.                 $this->connect->exec("SET CHARACTER SET `utf8`");
  17.             }catch(PDOException $error)
  18.             {
  19.                 print_r($error->getMessage()); 
  20.             }
  21.             return $this->connect;
  22.         }
  23.     }
  24. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement