daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     /**
  3.      * Database Class - Manager pour les autres classes
  4.      */
  5.     class Database
  6.     {
  7.         const host = 'localhost';
  8.         const dbname = 'food';
  9.         const user = 'root';
  10.         const mdp = '';
  11.  
  12.         private $_db;
  13.  
  14.         //Methode de connection à la base de données
  15.         public function getConnection()
  16.         {
  17.             $this->_db = new PDO('mysql:host='.self::host.';dbname='.self::dbname,self::user,self::mdp);
  18.         }
  19.         //Fonction d'hydratation des différentes classes
  20.         public function hydrate($array){
  21.             foreach ($array as $key => $value)
  22.             {
  23.                 $method = 'set'.ucfirst($key);
  24.                 if (method_exists($this, $method))
  25.                 {
  26.                     $this->$method(empty($value) ? null : $value);
  27.                 }
  28.             }
  29.         }
  30.         //Methode de requete
  31.         public function PreparedQueryOne($sql,$array){
  32.             $req = $this->_db->prepare($sql);
  33.             $req->execute($array);
  34.         }
  35.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top