Advertisement
Guest User

Untitled

a guest
Nov 4th, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2.   class DB{
  3.             private $host = 'localhost';
  4.             private $username = 'root';
  5.             private $password = '';
  6.             private $database = 'toutiyai';
  7.             private $db;
  8.            
  9.             public function __construct($host=null, $username=null, $password=null, $database=null)
  10.             {
  11.                 if($host!= null)
  12.                 {
  13.                     $this->host = $host;
  14.                     $this->username = $username;
  15.                     $this->password = $password;
  16.                     $this->database = $database;
  17.                 }
  18.                 try{
  19.                 $this->db = new PDO('mysql:host='.$this->host.' ;dbname='.$this->database, $this->username,
  20.                                     $this->password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'));
  21.                 }catch(PDOException $e){
  22.                     die('<h1>impossible de se connecter a la base de donnee</h1>');
  23.                 }
  24.             }
  25.          
  26.          
  27.           }
  28.  
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement