link) == "boolean") /* emulation of an persistent connection, earlier connection is used, if it exists */ { $this->link = @mysql_connect($GLOBALS["cfg"]["mysql"]["host"], $GLOBALS["cfg"]["mysql"]["user"], $GLOBALS["cfg"]["mysql"]["pwd"]); if(!$this->link) { throw new Exception("Error while connecting to database host, MySQL said: ".mysql_error()); } $select = @mysql_select_db($GLOBALS["cfg"]["mysql"]["db"], $this->link); if(!$select) { throw new Exception("Error while selecting database, MySQL said: ".mysql_error()); } } if($query != false) { $this->query($query); } } public function __destruct() /* closes database connection on last call of the class */ { if(gettype($this->link) != "boolean") { print "2"; @mysql_close($this->link); } else { throw new Exception("Error while trying to close a MySQL-Connection, which is not active anymore."); } } public function query($query) /* make a query against the database, standard-result is an object */ { if(!is_null($this->query_str)) { $this->reset(); } $this->query_str = $query; $this->query_handler = @mysql_query($this->query_str); if(!$this->query_handler) { throw new Exception("Error while querying the database, MySQL said: ".mysql_error()); } $GLOBALS["queries"][] = $query; } public function result($resultmode = false) /* gets the result in a variable format */ { if(!$this->query_handler) { throw new Exception("Error while getting results, result-handler empty - did you do a valid query before?"); } if($resultmode == "assoc") { return @mysql_fetch_assoc($this->query_handler); } else { return @mysql_fetch_object($this->query_handler); } } public function rows() /* gives the number of result-rows of previous query */ { if($this->query_handler != false) { return mysql_num_rows($this->query_handler); } else { throw new Exception("Error while getting number of results rows, no valid query before"); } } protected function reset() /* don't let us reset from object context */ { $this->query_handler = false; $this->query_str = NULL; } public function query_str() { return $this->query_str; } /* safely returns query-string */ public function query_handler() { return $this->query_handler; } /* safely returns query-handler */ public function link_handler() { return $this->link; } /* safely returns the handler of the current connection */ } ?>