username = $username; $this->password = $password; $this->host = $host; $this->db_name = $db; try { $this->dbc = mysqli_connect($this->host, $this->username, $this->password, $this->db_name); // set encoding mysqli_set_charset($this->dbc, 'utf8'); } catch(Exception $e) { echo "ERROR - Failed to open stream to database"; } } function query($query) { try { $r = mysqli_query($this->dbc, $query); $this->count++; return $r; } catch(Exception $e) { echo "There was a problem with the database, We apologize for the inconvenience ".$e->getMessage(); } } function fetchresult($r) { // get the result(s) of an executed query. try { if(mysqli_num_rows($r) >= 1) { // get the result $row = mysqli_fetch_array($r); $this->results[] = $row; return $row; } else { return false; } } catch(Exception $e) { echo "There was an error in processing your request. We are sorry for the inconvenience."; } } function numrows($query) { $r = $this->query($query); return mysqli_num_rows($r); } function escape_data($data) { return trim(mysqli_real_escape_string($this->dbc, $data)); } } ?>