Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. <?php
  2.  
  3. class DB {
  4.  
  5. private $_dbhost = DBHOST;
  6. private $_dbuser = DBUSER;
  7. private $_dbpass = DBPASS;
  8. private $_dbname = DBNAME;
  9. private $_dbchar = DBCHAR;
  10.  
  11. private static $_instance = null;
  12.  
  13. public $_connection;
  14. public $_prefix;
  15. public $_query;
  16. public $_error = [];
  17. public $_result = [];
  18. public $_count = 0;
  19. public $_affected_rows = 0;
  20. public $_columns;
  21. public $_operators = [
  22. '=', '<', '>', '<=', '>=', '<>', '!=', '<=>',
  23. 'like', 'like binary', 'not like', 'between', 'ilike',
  24. '&', '|', '^', '<<', '>>',
  25. 'rlike', 'regexp', 'not regexp',
  26. '~', '~*', '!~', '!~*', 'similar to',
  27. 'not similar to', 'not ilike', '~~*', '!~~*',
  28. ];
  29.  
  30. public static function getInstance()
  31. {
  32. if (!self::$_instance) {
  33. self::$_instance = new self();
  34. }
  35. return self::$_instance;
  36. }
  37.  
  38. public function __construct() {
  39. $this->_connection = new mysqli($this->_dbhost, $this->_dbuser, $this->_dbpass, $this->_dbname);
  40. if (mysqli_connect_errno()) {
  41. trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
  42. }
  43. $this->_connection->set_charset($this->_dbchar);
  44. }
  45.  
  46. public function safe($var)
  47. {
  48. $data = @unserialize($var);
  49. if ($data === false) {
  50. $var = $this->_connection->real_escape_string(trim($var));
  51. }
  52. return $var;
  53. }
  54.  
  55. public function prefix($prefix)
  56. {
  57. $this->_prefix = $this->safe($prefix);
  58. }
  59.  
  60. public function table($table)
  61. {
  62. $this->_table = $this->safe($table);
  63. return $this;
  64. }
  65.  
  66. public function error($message)
  67. {
  68. $this->_error[] = $message;
  69. }
  70.  
  71. public function getError()
  72. {
  73. $number = 1;
  74. $log = '';
  75. foreach ($this->_error as $error) {
  76. $log .= "#" . $number . ": " . $error . "<br />";
  77. $number++;
  78. }
  79. return $log;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement