Guest User

Untitled

a guest
Nov 8th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 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.               if($host != null){
  11.                 $this->host = $host;
  12.                 $this->username = $username;
  13.                 $this->password = $password;
  14.                 $this->database = $database;
  15.               }
  16.               try{
  17.               $this->db = new PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->username, $this->password,
  18.                             array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8',
  19.                                   PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING
  20.                                   ));
  21.               }catch(PDOException $e){
  22.               die("<h1>impossible de se connecter a la base de données</h1>");}
  23.             }
  24.             public function query($sql, $data = array()){
  25.               $req = $this->db->prepare($sql);
  26.               $req->execute($data);
  27.               return $req->fetchAll(PDO::FETCH_OBJ);
  28.             }
  29.     }
  30.    
  31.        
  32.    
  33. ?>
Add Comment
Please, Sign In to add comment