<?php
if(!defined('PK_MAGIC'))
die('hack or what?');
/* */
class DB
{
var $connection_id = false;
var $result_id = false;
/* */
function DB()
{
$this->connection_id = false;
$this->result_id = false;
}
/* */
function connect($db_server, $db_port, $db_name, $db_user, $db_password)
{
$this->connection_id = @mysql_connect($db_server . ($db_port == '' ? '' : ':' . $db_port), $db_user, $db_password);
$this->result_id = false;
if($this->connection_id && @mysql_select_db($db_name))
{
return $this->connection_id;
}
return false;
}
/* */
function close()
{
if($this->connection_id)
{
if(@mysql_close($this->connection_id))
{
$this->connection_id = false;
return true;
}
}
return false;
}
/* */
function query($query_string)
{
if($this->result_id = @mysql_query($query_string, $this->connection_id))
{
return $this->result_id;
}
return false;
}
/* */
function fetch_row($result_id = false)
{
if($this->connection_id)
{
if($result_id == false)
{
$result_id = $this->result_id;
}
if($result_id)
{
if($row = @mysql_fetch_assoc($result_id))
{
return $row;
}
}
}
return false;
}
/* */
function fetch_rowset($result_id = false)
{
if($this->connection_id)
{
if($result_id == false)
{
$result_id = $this->result_id;
}
if($result_id)
{
$rowset = array();
$rows = @mysql_num_rows($result_id);
while($rows--)
{
if($row = @mysql_fetch_assoc($result_id))
{
$rowset[] = $row;
}
else
{
return false;
}
}
return $rowset;
}
}
return false;
}
/* */
function free_result($result_id = false)
{
if($this->connection_id)
{
if($result_id == false)
{
$result_id = $this->result_id;
$this->result_id = false;
}
if($result_id)
{
if(@mysql_free_result($result_id))
{
return true;
}
}
}
return false;
}
/* */
function insert_id()
{
if($this->connection_id)
{
if($insert_id = @mysql_insert_id($this->connection_id))
{
return $insert_id;
}
}
return false;
}
/* */
function affected_rows()
{
if($this->connection_id)
{
if($affected_rows = @mysql_affected_rows($this->connection_id))
{
return $affected_rows;
}
}
return false;
}
/* */
function num_rows($result_id = false)
{
if($this->connection_id)
{
if($result_id == false)
{
$result_id = $this->result_id;
}
if($result_id)
{
if($num_rows = @mysql_num_rows($result_id))
{
return $num_rows;
}
}
}
return false;
}
/* */
function escape($query_string)
{
return mysql_real_escape_string($query_string);
}
/* */
function escape_pattern($query_string)
{
$query_string = str_replace(array('%', '_'), array('\\%', '\\_'), $query_string);
$query_string = str_replace(array('*', '?'), array('%', '_'), $query_string);
$query_string = mysql_real_escape_string($query_string);
return str_replace(array('\\\\%', '\\\\_'), array('\\%', '\\_'), $query_string);
}
/* */
function error()
{
if($this->connection_id)
{
return mysql_error($this->connection_id);
}
return false;
}
}
?>