Advertisement
Guest User

Untitled

a guest
Dec 9th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. Class MySQL extends PDO {
  3.     private $engine     = 'mysql';
  4.     private $host       = 'localhost';
  5.     private $database   = 'base';
  6.     private $user       = 'root';
  7.     private $pass       = '';
  8.    
  9.     private $dbh;
  10.     private $smth;
  11.     private $error;
  12.    
  13.     public function __construct(){
  14.         $dsn = 'mysql:host='.$this->host.';dbname='.$this->database;
  15.         $options = array(PDO::ATTR_PERSISTENT => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
  16.         try{
  17.             $this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
  18.         }catch(PDOException $e){
  19.             $this->error = $e->getMessage();
  20.         }
  21.     }
  22.    
  23.     public function query($query){
  24.         $this->stmt = $this->dbh->prepare($query);
  25.     }
  26.     public function runfastquery($query){
  27.         $this->stmt = $this->dbh->prepare($query);
  28.         $this->stmt->execute();
  29.         return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
  30.     }
  31.     public function execute(){
  32.             return $this->stmt->execute();
  33.     }
  34.     public function bind($param, $value, $type = null){
  35.         if (is_null($type)) {
  36.             switch (true) {
  37.                 case is_int($value):
  38.                     $type = PDO::PARAM_INT;
  39.                     break;
  40.                 case is_bool($value):
  41.                     $type = PDO::PARAM_BOOL;
  42.                     break;
  43.                 case is_null($value):
  44.                     $type = PDO::PARAM_NULL;
  45.                     break;
  46.                 default:
  47.                     $type = PDO::PARAM_STR;
  48.             }
  49.         }
  50.         $this->stmt->bindValue($param, $value, $type);
  51.     }
  52.     public function resultset(){
  53.         $this->execute();
  54.         return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
  55.     }
  56.     public function getCount(){
  57.         return $this->stmt->fetch(PDO::FETCH_NUM)[0];
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement