- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
<?
global $db;
$db=new db(HOST,USER,PASS,DBNAME); //подключение к бд
class db{
public $SumQuerys=false; //Temp Var
public $Vtime; //Temp time summ
public $td; //Temp date
public $db_id= false;
public $query_num=0;
public $query_id=NULL;
public $mysql_error=FALSE;
public $mysql_error_num=NULL;
public $last_query=NULL;
var $error=0;
function __construct($host='',$user='',$pas='',$bd=''){
$this->db_id=mysql_connect($host,$user,$pas) or die('db connect error');
mysql_select_db($bd,$this->db_id) or die("db: '$bd' select error");
mysql_query('SET NAMES utf8');
}
function __destruct(){
$this->close();
if ($this->SumQuerys){
#print "<table style='font-size:10px;border-collapse:collapse;border:1px dotted black' border=1>".$this->SumQuerys."<tr><td><b>$this->Vtime</b></td><td></td></table>";
}
}
function query($query, $show_error=true){
$time = microtime(true);
$this->last_query = $query;
if(!($this->query_id = mysql_query($query, $this->db_id))){
$this->error=1;
$this->mysql_error = mysql_error();
$this->mysql_error_num=mysql_errno();
if($show_error){
$this->display_error($this->mysql_error, $this->mysql_error_num, $query);
}
} else {$this->error=0;}
$this->query_num ++;
// ----------------------------------------------------------------------------
$time = round(microtime(true)-$time,5);
if($time>0.003){
$alert = "color:red";
}
$this->Vtime += $time;
@$this->SumQuerys .= "<tr style='$alert'><td>".$time."</td><td>".$query.'</td></tr>';
//------------------------------------------------------------------------------
return $this->query_id;
}
function qrow($query){
$this->query($query);
return mysql_fetch_row($this->query_id);
}
function get_row($query_id = ''){
if ($query_id == '') $query_id = $this->query_id;
return mysql_fetch_assoc($query_id);
}
function get_array($query_id = ''){
if ($query_id == '') $query_id = $this->query_id;
return mysql_fetch_array($query_id);
}
function fetch($query_id = ''){
global $d;
if ($query_id == '') $query_id = $this->query_id;
return $d=@mysql_fetch_object($query_id);
}
function fetchAll($field = ''){
while ($d=$this->fetch($this->query_id)){
if ($field == ''){
$arr[] = $d;
} else {
$arr[] = $d->$field;
}
}
return @$arr;
}
function qAll($query){
$this->query($query);
return $this->fetchAll();
}
function fetch_row($query_id = ''){
global $d;
if ($query_id == '') $query_id = $this->query_id;
return $d=@mysql_fetch_row($query_id);
}
function qfetch($query){
global $d;
$this->query($query);
return $d=@mysql_fetch_object($this->query_id);
}
function num_rows($query_id = ''){
if ($query_id == '') $query_id = $this->query_id;
return mysql_num_rows($query_id);
}
function insert_id() {
return mysql_insert_id($this->db_id);
}
Bobby 13.08.2009 10:16 # +1
guest 13.08.2009 15:48 # +1
guest 13.08.2009 23:26 # +1
guest 20.08.2009 18:33 # +1