Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************
- * Bitcoin Cash (BCH/BCC)
- * 1DaXBwnUgWcPuNvEzei9KMkodjxF6rSSw6
- *
- */
- <?php
- class db {
- /**
- * string containing the user's query string
- */
- private $query;
- private $query_results;
- function __construct($username, $password, $connect_now = false, $database = 'default', $host = 'localhost', $port = '3306') {
- $this->username = $username;
- $this->password = $password;
- $this->host = $host;
- $this->port = $port;
- $this->name = $database;
- $this->query_results = NULL;
- if($connect_now)
- if(!$this->connect()) die('ERROR: Unable to connect to database');
- $this->parent = parent::$object;
- parent::$children[get_class($this)] = $this;
- }
- public function connect() {
- $this->connection = new mysqli($this->host, $this->username, $this->password, $this->name);
- if(!$this->hasValidDbConnection()) return false;
- return true;
- }
- public function run_query($query, $close_connection = false, $array_type = false) {
- if(!$this->hasValidDbConnection()) return false;
- $this->query_results = $return = $this->connection->query($query);
- if($array_type !== false) {
- $fetch = 'fetch_'.$array_type;
- $return = [];
- while($row = $this->query_results->$fetch())
- $return[] = $row;
- }
- if($close_connection) $this->close();
- return $return;
- }
- public function run_multi_query($query, $close_connection = false) {
- if(!$this->hasValidDbConnection()) return false;
- $return = $this->connection->multi_query($query);
- if($close_connection) $this->close();
- return $return;
- }
- public function close() {
- // This line caused db query results to clear before returning to calling function
- // $this->query_results->free();
- $this->query_results = NULL;
- $this->connection->kill($this->connection->thread_id);
- $this->connection->close();
- }
- private function hasValidDbConnection() {
- return (bool) $this->connection;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment