Guest User

Untitled

a guest
Oct 16th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. /*********************************************************
  2. * Bitcoin Cash (BCH/BCC)
  3. * 1DaXBwnUgWcPuNvEzei9KMkodjxF6rSSw6
  4. *
  5. */
  6. <?php
  7.  
  8. class db {
  9.  
  10. /**
  11. * string containing the user's query string
  12. */
  13. private $query;
  14.  
  15. private $query_results;
  16.  
  17. function __construct($username, $password, $connect_now = false, $database = 'default', $host = 'localhost', $port = '3306') {
  18. $this->username = $username;
  19. $this->password = $password;
  20. $this->host = $host;
  21. $this->port = $port;
  22. $this->name = $database;
  23.  
  24. $this->query_results = NULL;
  25.  
  26. if($connect_now)
  27. if(!$this->connect()) die('ERROR: Unable to connect to database');
  28.  
  29. $this->parent = parent::$object;
  30. parent::$children[get_class($this)] = $this;
  31. }
  32.  
  33. public function connect() {
  34. $this->connection = new mysqli($this->host, $this->username, $this->password, $this->name);
  35.  
  36. if(!$this->hasValidDbConnection()) return false;
  37.  
  38. return true;
  39. }
  40.  
  41. public function run_query($query, $close_connection = false, $array_type = false) {
  42. if(!$this->hasValidDbConnection()) return false;
  43.  
  44. $this->query_results = $return = $this->connection->query($query);
  45.  
  46. if($array_type !== false) {
  47. $fetch = 'fetch_'.$array_type;
  48.  
  49. $return = [];
  50. while($row = $this->query_results->$fetch())
  51. $return[] = $row;
  52. }
  53.  
  54. if($close_connection) $this->close();
  55.  
  56. return $return;
  57. }
  58.  
  59. public function run_multi_query($query, $close_connection = false) {
  60. if(!$this->hasValidDbConnection()) return false;
  61.  
  62. $return = $this->connection->multi_query($query);
  63.  
  64. if($close_connection) $this->close();
  65.  
  66. return $return;
  67. }
  68.  
  69. public function close() {
  70. // This line caused db query results to clear before returning to calling function
  71. // $this->query_results->free();
  72. $this->query_results = NULL;
  73.  
  74. $this->connection->kill($this->connection->thread_id);
  75. $this->connection->close();
  76. }
  77.  
  78. private function hasValidDbConnection() {
  79. return (bool) $this->connection;
  80. }
  81.  
  82. }
  83.  
  84. ?>
Add Comment
Please, Sign In to add comment