<?php
class MySQL_class {
var $db, $id, $result, $rows, $data, $a_rows;
function Create ($db) {
if (!$this->db && !$db) {
$this->db = "generator";
} else {
$this->db = $db;
}
$this->id = @mysql_connect() or
MySQL_ErrorMsg("Unable to connect to MySQL server");
$this->selectdb($this->db);
}
function SelectDB ($db) {
@mysql_select_db($db, $this->id) or
MySQL_ErrorMsg ("Unable to select database: $db");
}
function Query ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
}
function QueryTry ($query) {
$res='';
$this->rows = 0;
$this->result = @mysql_query($query, $this->id) or
$res=mysql_error();
if ($res=='') {
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
}
return($res);
}
# Use this function if the query will only return a
# single data element.
function QueryItem ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
$this->data = @mysql_fetch_array($this->result);
return($this->data[0]);
}
# This function is useful if the query will only return a
# single row.
function QueryRow ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->id);
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch data from query: $query");
return($this->data);
}
function Fetch ($row) {
@mysql_data_seek($this->result, $row) or
MySQL_ErrorMsg ("Unable to seek data row: $row");
$this->data = @mysql_fetch_array($this->result) or
MySQL_ErrorMsg ("Unable to fetch row: $row");
}
function Insert ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform insert: $query");
$this->a_rows = @mysql_affected_rows($this->id);
}
function InsertID () {
return mysql_insert_id();
}
function Update ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform update: $query");
$this->a_rows = @mysql_affected_rows($this->id);
}
function Delete ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform Delete: $query");
$this->a_rows = @mysql_affected_rows($this->id);
}
}
function MySQL_ErrorMsg ($msg) {
echo("</ul></dl></ol>\n");
echo("</table></script>\n");
$text = "<font color=\"#ff0000\" size=+2><p>Error: $msg :";
$text .= mysql_error();
$text .= "</font>\n";
die($text);
}
function quote ($value) {
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
$value = "'" . addslashes($value) . "'";
return $value;
}
?>