fabi0

Untitled

May 13th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.99 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * To change this license header, choose License Headers in Project Properties.
  5.  * To change this template file, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8.  
  9. /**
  10.  * Description of validate
  11.  *
  12.  * @author fabi0
  13.  */
  14.  
  15. class DB {
  16.  
  17.     private static $_instance = NULL;
  18.     private $_pdo,
  19.             $_query,
  20.             $_error = false,
  21.             $_result,
  22.             $_count = 0,
  23.             $_user = 'root',
  24.             $_password = '',
  25.             $_database = 'iziforum',
  26.             $_host = '127.0.0.1';
  27.  
  28.     private function __construct() {
  29.         try {
  30.             $this->_pdo = new \PDO('mysql:host=' . $this->_host . ';dbname=' .
  31.                     $this->_database . ';charset=utf8', $this->_user, $this->_password);
  32.         } catch (\PDOException $e) {
  33.             die($e->getMessage());
  34.         }
  35.     }
  36.  
  37.     public static function getInstance() {
  38.         if (!isset(self::$_instance)) {
  39.             self::$_instance = new DB();
  40.         }
  41.         return self::$_instance;
  42.     }
  43.  
  44.     public function query($sql, $params = array()) {
  45.         $this->_error = FALSE;
  46.         if ($this->_query = $this->_pdo->prepare($sql)) {
  47.             if (count($params)) {
  48.                 foreach ($params as $field => $values) {
  49.                     $this->_query->bindParam($field, $values['param'], $values['type']);
  50.                 }
  51.             }
  52.  
  53.             if ($this->_query->execute()) {
  54.                 $this->_result = $this->_query->fetchAll(\PDO::FETCH_OBJ);
  55.                 $this->_count = $this->_query->rowCount();
  56.             } else {
  57.                 $this->_error = $this->_query->errorInfo();
  58.             }
  59.         }
  60.         return $this;
  61.     }
  62.  
  63.     public function getErrors() {
  64.         return $this->_error;
  65.     }
  66.  
  67.     public function getResult() {
  68.         return $this->_result;
  69.     }
  70.  
  71.     public function getCount() {
  72.         return $this->_count;
  73.     }
  74.  
  75.     public function lastID() {
  76.        
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment