Advertisement
Guest User

Untitled

a guest
Sep 5th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.49 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 $conn;
  9.         public function dbConnection()
  10.         {
  11.             $this->conn=null;
  12.             try
  13.             {
  14.                 $this->conn=new PDO("mysql:host=".$this->host.";dbname=".$this->db_name,$this->username,$this->password);
  15.                 $this->conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  16.             }catch(PDOException $e)
  17.             {
  18.                 print_r($e->getMessage()); 
  19.             }
  20.             return $this->conn;
  21.         }
  22.     }
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement