Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- * Description of validate
- *
- * @author fabi0
- */
- class DB {
- private static $_instance = NULL;
- private $_pdo,
- $_query,
- $_error = false,
- $_result,
- $_count = 0,
- $_user = 'root',
- $_password = '',
- $_database = 'iziforum',
- $_host = '127.0.0.1';
- private function __construct() {
- try {
- $this->_pdo = new \PDO('mysql:host=' . $this->_host . ';dbname=' .
- $this->_database . ';charset=utf8', $this->_user, $this->_password);
- } catch (\PDOException $e) {
- die($e->getMessage());
- }
- }
- public static function getInstance() {
- if (!isset(self::$_instance)) {
- self::$_instance = new DB();
- }
- return self::$_instance;
- }
- public function query($sql, $params = array()) {
- $this->_error = FALSE;
- if ($this->_query = $this->_pdo->prepare($sql)) {
- if (count($params)) {
- foreach ($params as $field => $values) {
- $this->_query->bindParam($field, $values['param'], $values['type']);
- }
- }
- if ($this->_query->execute()) {
- $this->_result = $this->_query->fetchAll(\PDO::FETCH_OBJ);
- $this->_count = $this->_query->rowCount();
- } else {
- $this->_error = $this->_query->errorInfo();
- }
- }
- return $this;
- }
- public function getErrors() {
- return $this->_error;
- }
- public function getResult() {
- return $this->_result;
- }
- public function getCount() {
- return $this->_count;
- }
- public function lastID() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment