Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. <?php
  2.  
  3. class MySQL {
  4.  
  5.     private static $instance = null;
  6.     private $config = array(
  7.             'server' => '',
  8.             'database' => '',
  9.             'user' => '',
  10.             'password' => '',
  11.             'prefix' => ''
  12.         ),
  13.         $queries = array(),
  14.         $mysqli = null;
  15.  
  16.     private function __construct() {}
  17.        
  18.     private function __clone() {}
  19.  
  20.     private function initialize() {
  21.         $this->config = parse_ini_file( SYSPATH.'/config/mysql.ini', false );
  22.         $this->open();
  23.     }
  24.    
  25.     public static function getInstance() {
  26.         if( self::$instance === null ) {
  27.             self::$instance = new self;
  28.             self::$instance->initialize();
  29.         }
  30.         return self::$instance;
  31.     }
  32.    
  33.     private function open() {
  34.         $this->mysqli =& new mysqli( $this->config['server'], $this->config['user'], $this->config['password'], $this->config['database'] );
  35.         if( $this->mysqli->connect_errno ) {
  36.             $Site = Site::getInstance();
  37.             die( "MySQL Connect Error: ".$this->mysqli->connect_error );
  38.         }
  39.     }
  40.  
  41.     public function close() {
  42.         $this->mysqli->close();
  43.     }
  44.  
  45.     public function escape($string="") {
  46.         $str = $this->mysqli->escape_string($string);
  47.         return $str;
  48.     }
  49.  
  50.     public function query($sql) {
  51.         $query = $this->mysqli->query($sql);
  52.         if( !$query ) {
  53.             $Site = Site::getInstance();
  54.             die( "MySQL Query Error: ".$this->mysqli->error );
  55.         }
  56.         array_push($this->queries,$sql);
  57.         return $query;
  58.     }
  59.  
  60.     public function getPrefix() {
  61.         return $this->config['prefix'].'_';
  62.     }
  63.  
  64.     public function countQueries() {
  65.         return count($this->queries);
  66.     }
  67.    
  68.     public function getQueries() {
  69.         return $this->queries;
  70.     }
  71.  
  72. }
  73.  
  74. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement