Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MySQL {
- private static $instance = null;
- private $config = array(
- 'server' => '',
- 'database' => '',
- 'user' => '',
- 'password' => '',
- 'prefix' => ''
- ),
- $queries = array(),
- $mysqli = null;
- private function __construct() {}
- private function __clone() {}
- private function initialize() {
- $this->config = parse_ini_file( SYSPATH.'/config/mysql.ini', false );
- $this->open();
- }
- public static function getInstance() {
- if( self::$instance === null ) {
- self::$instance = new self;
- self::$instance->initialize();
- }
- return self::$instance;
- }
- private function open() {
- $this->mysqli =& new mysqli( $this->config['server'], $this->config['user'], $this->config['password'], $this->config['database'] );
- if( $this->mysqli->connect_errno ) {
- $Site = Site::getInstance();
- die( "MySQL Connect Error: ".$this->mysqli->connect_error );
- }
- }
- public function close() {
- $this->mysqli->close();
- }
- public function escape($string="") {
- $str = $this->mysqli->escape_string($string);
- return $str;
- }
- public function query($sql) {
- $query = $this->mysqli->query($sql);
- if( !$query ) {
- $Site = Site::getInstance();
- die( "MySQL Query Error: ".$this->mysqli->error );
- }
- array_push($this->queries,$sql);
- return $query;
- }
- public function getPrefix() {
- return $this->config['prefix'].'_';
- }
- public function countQueries() {
- return count($this->queries);
- }
- public function getQueries() {
- return $this->queries;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement