Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.49 KB | None | 0 0
  1. <?php
  2.     class Database{
  3.         private $host = "";
  4.         private $db_name = ""; 
  5.         private $user = "";
  6.         private $pass = "";
  7.         public $conn;  
  8.        
  9.         function getConnection(){  
  10.             try{   
  11.                 $this->conn = null;
  12.                 $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->user, $this->pass);
  13.                 $this->conn->exec("set names utf8");
  14.             }catch(PDOException $exception){
  15.                 echo "error" . $exception->getMessage();
  16.             }
  17.             return $this->conn;
  18.         }
  19. }
  20. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement