source: devel/www/database.php@ 131

Last change on this file since 131 was 131, checked in by george, 16 years ago
  • Opraveno: Chyba odebírání odpojených uživatelů.
  • Přidáno: Funkce pro zobrazení velikosti čitelné lidmi.
File size: 2.4 KB
Line 
1<?php
2
3// Extended database class
4// Date: 2007-07-19
5
6class Database extends mysqli
7{
8 var $Prefix = '';
9 var $LastQuery = '';
10
11 function query($Query)
12 {
13 $this->LastQuery = $Query;
14 return(parent::query($Query));
15 }
16
17 function select($Table, $What = '*', $Condition = 1)
18 {
19 $this->LastQuery = "SELECT ".$What." FROM `".$this->Prefix.$Table."` WHERE ".$Condition;
20 return($this->query($this->LastQuery));
21 }
22
23 function delete($Table, $Condition)
24 {
25 $this->LastQuery = "DELETE FROM `".$this->Prefix.$Table."` WHERE ".$Condition;
26 $this->query($this->LastQuery);
27 }
28
29 function insert($Table, $Data)
30 {
31 $Name = '';
32 $Values = '';
33 foreach($Data as $Key => $Value)
34 {
35 $Value = strtr($Value, '"', '\"');
36 $Name .= ',`'.$Key.'`';
37 if($Value == 'NOW()') $Values .= ",".$Value;
38else if($Value == 'UUID()') $Values .= ",".$Value;
39 else $Values .= ",'".$Value."'";
40 }
41 $Name = substr($Name, 1);
42 $Values = substr($Values, 1);
43 $this->LastQuery = 'INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')';
44 $this->query($this->LastQuery);
45 }
46
47 function update($Table, $Condition, $Data)
48 {
49 $Values = '';
50 foreach($Data as $Key => $Value)
51 {
52 $Value = strtr($Value, '"', '\"');
53 if($Value != 'NOW()') $Value = "'".$Value."'";
54 $Values .= ", ".$Key."=".$Value;
55 }
56 $Values = substr($Values, 2);
57 $this->LastQuery = 'UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')';
58 $this->query($this->LastQuery);
59 }
60
61 function replace($Table, $Data)
62 {
63 $Name = '';
64 $Values = '';
65 foreach($Data as $Key => $Value)
66 {
67 $Value = strtr($Value, '"', '\"');
68 $Name .= ',`'.$Key.'`';
69 if($Value == 'NOW()') $Values .= ",".$Value;
70 else $Values .= ',"'.$Value.'"';
71 }
72 $Name = substr($Name, 1);
73 $Values = substr($Values, 1);
74 //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br>');
75 $this->LastQuery = 'REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')';
76 $this->query($this->LastQuery);
77 //echo($this->error().'<br>');
78 }
79
80 function charset($Charset)
81 {
82 $this->LastQuery = 'SET CHARACTER SET '.$Charset;
83 $this->query($this->LastQuery);
84 }
85
86}
87
88?>
Note: See TracBrowser for help on using the repository browser.