|

|

<?php
class DB
{
var $Hostname = "localhost";
var $Username = "root";
var $Password = "";
var $Database = "b-m";
var $Connect;
var $DBselect = 1;
var $ShowError = 1;
var $Selected;
function DB($host="", $user="", $pass="", $db="", $dbselect="")
{
global $hostname, $dbusername, $dbpassword, $dbname, $conntype, $debug;
if ($host != "" || $hostname != "")
{
$host != "" ? $this->Hostname = $host : $this->Hostname = $hostname;
}
if ($user != "" || $dbusername != "")
{
$user != "" ? $this->Username = $user : $this->Username = $dbusername;
}
if ($pass != "" || $dbpassword != "")
{
$pass != "" ? $this->Password = $pass : $this->Password = $dbpassword;
}
if ($db != "" || $dbname != "")
{
$db != "" ? $this->Database = $db : $this->Database = $dbname;
}
if ($dbselect != "") $this->DBselect = $dbselect;
if ($debug != "") $this->ShowError = $debug;
if ($conntype ==0)
{
$this->Connect = @mysql_connect($this->Hostname,$this->Username,$this->Password);
}
else
{
$this->Connect = @mysql_pconnect($this->Hostname,$this->Username,$this->Password);
}
if (!$this->Connect)
{
if ($this->ShowError == 1)
{
return $this->db_error("Не удалось установить соединение с базой данных. Сообщите об этом администратору.");
}
return false;
}
if ($this->DBselect == 1)
{
if (!@mysql_select_db($this->Database,$this->Connect))
{
if ($this->ShowError == 1)
{
return $this->db_error("Ошибка MySQL: ",$this->Connect);
}
return false;
}
return $this->Selected = $this->Database;
}
}
function db_select()
{
if (!@mysql_select_db($this->Database,$this->Connect))
{
if ($this->ShowError == 1)
{
return $this->db_error("Ошибка MySQL: ",$this->Connect);
}
return false;
}
return $this->Selected = $this->Database;
}
function db_create()
{
if (!@mysql_create_db($this->Database))
{
if ($this->ShowError == 1)
{
return $this->db_error("Невозможно создать базу данных, указанную в конфигурационном файле");
}
return false;
}
return true;
}
function db_close()
{
mysql_close($this->Connect);
}
function db_error($message,$id="")
{
if ($id)
{
$message .= mysql_errno($id) . " " . mysql_error($id);
}
echo "<br />" . $message . "<br /><br />";
}
}
class DB_query
{
var $query = 0;
var $sql = "";
var $row = array();
var $obj;
var $res;
var $numrows;
var $rows = 0;
var $errors = 1;
var $result = false;
function DB_query($db, $q)
{
global $debug, $cache_db, $cache_exp;
if ($debug != "") $this->errors = $debug;
if ($db->Connect)
{
if (!$this->query = @mysql_query($q))
{
if ($this->errors == 1)
return $this->db_query_error("MySQL Error: ",$db->Connect);
}
$this->sql = $q;
$this->result = true;
return $this->result;
}
}
function db_fetch_array()
{
return $this->row = @mysql_fetch_array($this->query, MYSQL_ASSOC);
}
function db_fetch_object()
{
return $this->obj = @mysql_fetch_object($this->query);
}
function db_fetch_row()
{
return $this->row = @mysql_fetch_row($this->query);
}
function db_num_rows()
{
return $this->numrows = @mysql_num_rows($this->query);
}
function db_result($x=0,$y="")
{
return $this->res = @mysql_result($this->query, $x, $y);
}
function db_insert_id()
{
global $db;
return mysql_insert_id($db->Connect);
}
function db_free_result()
{
@mysql_free_result($this->query);
}
function db_query_error($message,$id="")
{
if ($id)
{
$message .= mysql_errno($id) . " " . mysql_error($id);
}
echo "<br />" . $message . "<br /><br />";
}
}
$db=NEW DB();
?>
|
|