daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Dec 16th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Sql extends PDO {
  4.  
  5.     private $conn;
  6.  
  7.     public function __construct(){
  8.  
  9.         $this->conn = new PDO("mysql:host=localhost;dbname=dbphp7", "admin", "admin");
  10.     }
  11.  
  12.     private function setParams($statment, $parameters = array()){
  13.        
  14.         foreach ($parameters as $key => $value) {
  15.            
  16.             $this->setParam($key, $value);
  17.         }  
  18.     }
  19.  
  20.     private function setParam($statment, $key, $value){
  21.  
  22.         $statment->bindParam($key,$value);
  23.     }
  24.  
  25.     public function query($rawQuery, $params = array()){
  26.  
  27.         $stmt = $this->conn->prepare($rawQuery);
  28.  
  29.         $this->setParam($stmt, $params);
  30.  
  31.         $stmt->execute();
  32.        
  33.         return $stmt;
  34.     }
  35.  
  36.     public function select($rawQuery, $params = array()):array
  37.     {
  38.  
  39.         $stmt = $this->query($rawQuery, $params);
  40.  
  41.         return $stmt->fetchAll(PDO::FETCH_ASSOC);
  42.  
  43.     }
  44. }
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