db = new mysqli($host, $uname, $passwd, $dbname); if ($this->db->connect_error) throw new Exception("Can not connect to MySQL database. Please check your configuration."); } /* * Close connection to DB */ protected function _close() : void { $this->db->close(); } /* * Make a query of the database. Return data as an array of arrays. */ protected function _query(string $query) : array { $arr = array(); $res = $this->db->query($query); if ($res === true || $res === false) return $arr; while (($arr[] = $res->fetch_assoc())); return array_filter($arr, function ($val) { return !is_null($val); }); } /* * Escape a string for use in a query */ protected function _esc(string $str) : string { return $this->db->real_escape_string($str); } } ?>