conn = new mysqli($server, $username, $password, $database); if ($this->conn->connect_error) throw new Exception('Failed to connect to the database.'); } public function CloseConnection() { if (isset($this->conn)) { $this->conn->close(); } } public function GetConnection() { return $this->conn; } public function Query($query) { return $this->conn->query($query); } public function QueryAndFetch($query) { $result = $this->Query($query); if ($result) { $assoc = $result->fetch_assoc(); $result->close(); return $assoc; } else { throw new Exception('Failed to execute query.'); } } public function EscapeString($str) { return $this->conn->real_escape_string($str); } public function FormatTimestampForSql($time) { return date('Y-m-d H:i:s', $time); } } ?>