Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DB {
- private $_dbhost = DBHOST;
- private $_dbuser = DBUSER;
- private $_dbpass = DBPASS;
- private $_dbname = DBNAME;
- private $_dbchar = DBCHAR;
- private static $_instance = null;
- public $_connection;
- public $_prefix;
- public $_query;
- public $_error = [];
- public $_result = [];
- public $_count = 0;
- public $_affected_rows = 0;
- public $_columns;
- public $_operators = [
- '=', '<', '>', '<=', '>=', '<>', '!=', '<=>',
- 'like', 'like binary', 'not like', 'between', 'ilike',
- '&', '|', '^', '<<', '>>',
- 'rlike', 'regexp', 'not regexp',
- '~', '~*', '!~', '!~*', 'similar to',
- 'not similar to', 'not ilike', '~~*', '!~~*',
- ];
- public static function getInstance()
- {
- if (!self::$_instance) {
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- public function __construct() {
- $this->_connection = new mysqli($this->_dbhost, $this->_dbuser, $this->_dbpass, $this->_dbname);
- if (mysqli_connect_errno()) {
- trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
- }
- $this->_connection->set_charset($this->_dbchar);
- }
- public function safe($var)
- {
- $data = @unserialize($var);
- if ($data === false) {
- $var = $this->_connection->real_escape_string(trim($var));
- }
- return $var;
- }
- public function prefix($prefix)
- {
- $this->_prefix = $this->safe($prefix);
- }
- public function table($table)
- {
- $this->_table = $this->safe($table);
- return $this;
- }
- public function error($message)
- {
- $this->_error[] = $message;
- }
- public function getError()
- {
- $number = 1;
- $log = '';
- foreach ($this->_error as $error) {
- $log .= "#" . $number . ": " . $error . "<br />";
- $number++;
- }
- return $log;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement