class db {
// integer
var $a_rows = 0;
var $link_id = 0;
var $query_id = 0;
var $errno = 0;
var $show_error = 0;
var $mail_error = 0;
var $port = 0;
var $query_c = 0;
var $rows = 0;
// string
var $errdesc = "";
var $hostname = "";
var $username = "";
var $password = "";
var $database = "";
var $techmail = "";
// array
var $record = array();
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 ) {
$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_resultid( $query ) {
$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 mysql_insert_id($this->link_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() {
$this->errdesc = mysql_error();
$this->errno = mysql_errno();
$message = "Error : $this->errdesc (#$this->errno)
\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 |