class db {
// integer
var $a_rows = 0; // beinhaltet den wert, der betroffenen zeilen bei benutzung von zB UPDATE
var $link_id = 0; // id der aktuellen verbindung
var $query_id = 0; // id des aktuellen querys
var $errno = 0; // mysql errorid
var $show_error = 1; // fehler anzeigen ? (1/0)
var $mail_error = 0; // fehler mailen ? (1/0)
var $port = 0; // port des mySQL-Servers
var $query_c = 0; // anzahl der ausgeführten querys
var $demo_modus = 0; // kein INSERT, UPDATE oder DELETE
// string
var $errdesc = ""; // mysql fehlerbeschreibung
var $hostname = ""; // mySQL-Hostname
var $username = ""; // mySQL-Username
var $password = ""; // mySQL-Passwort
var $database = ""; // mySQL-Datenbank
var $techmail = ""; // eMail des users, nur nötig wenn $mail_error 1 ist
// array
var $record = array(); // resultierende datensätze aus mysql_fetch_array etc.
function connect() {
if ($this->link_id == 0) {
if ( ereg(":",$this->hostname) ) {
list($host,$port) = explode(":",$this->hostname);
$this->port = $port;
} else {
$this->port = 3306;
}
$this->link_id = @mysql_connect($this->hostname.':'.$this->port,$this->username,$this->password);
if ( !$this->link_id ) {
$this->error("can't connect to ".$this->username."@".$this->hostname.':'.$this->port);
}
if ($this->database != "") {
$this->select_db($this->database);
}
}
}
function select_db( $database = "" ) {
if ($database != "") {
$this->database = $database;
}
if( !@mysql_select_db($this->database, $this->link_id) ) {
$this->error("cannot use database ".$this->database);
}
}
function query( $query ) {
if(preg_match("=^(UPDATE|INSERT|DELETE)=i",$query) && $this->demo_modus == 1)return $this->query_id;
$this->query_id = mysql_query( $query, $this->link_id );
$this->query_c++;
if ( !$this->query_id ) {
$this->error("Invalid SQL: \"$query\"");
}
$this->a_rows = @mysql_affected_rows($this->query_id);
return $this->query_id;
}
function query_first($query) {
$this->query($query);
$returnarray=$this->fetch_array($this->query_id);
$this->free_result($this->query_id);
return $returnarray;
}
function unbuffered_query($query) {
if(preg_match("=^(UPDATE|INSERT|DELETE)=i",$query) && $this->demo_modus == 1)return $this->query_id;
$this->query_id = mysql_unbuffered_query($query,$this->link_id);
if ( !$this->query_id ) {
$this->error("Invalid SQL: \"$query\"");
}
return $this->query_id;
}
function fetch_row( $query_id = -1 ) {
if ( $query_id != -1) {
$this->query_id = $query_id;
}
$this->record = @mysql_fetch_row( $this->query_id );
return $this->record;
}
function fetch_array( $query_id = -1 ) {
if ( $query_id != -1) {
$this->query_id = $query_id;
}
$this->record = @mysql_fetch_array( $this->query_id );
return $this->record;
}
function fetch_object( $query_id = -1 ) {
if ( $query_id != -1) {
$this->query_id = $query_id;
}
$this->record = @mysql_fetch_object( $this->query_id );
return $this->record;
}
function quote($value) {
return "'". preg_replace("/'/", "''", $value) ."'";
}
function free_result ($query_id = -1) {
if ($query_id != -1) {
$this->query_id = $query_id;
}
return mysql_free_result ($this->query_id);
}
function num_rows($query_id = -1) {
if ($query_id != -1) {
$this->query_id = $query_id;
}
return mysql_num_rows ($this->query_id);
}
function insert_id() {
return mysql_insert_id ($this->link_id);
}
function stats($print = 0) {
if ($print == 0) {
return $this->query_c;
} else {
print ($this->query_c);
}
}
function error($msg="") {
$this->errdesc = mysql_error();
$this->errno = mysql_errno();
$message = "Error : $this->errdesc (#$this->errno)
\n";
//$message.= $msg."
\n";
$message.= "Date : ".date("D, F j, Y H:i:s")."
\n";
$message.= "Script : ".$_SERVER["REQUEST_URI"]."
\n";
$message.= "IP : ".$_SERVER["REMOTE_ADDR"]."
\n";
$message.= "Host : ".gethostbyaddr($_SERVER["REMOTE_ADDR"])."
\n";
$message.= "Querys : ".$this->query_c."
\n";
if ($this->show_error == 1) {
print("
$message |