source: www/database.php@ 30

Last change on this file since 30 was 30, checked in by george, 17 years ago

Opraveno: Sestavení SQL dotazu v metodě replace.

File size: 1.9 KB
Line 
1<?
2
3// Extended database class
4// Date: 2007-07-19
5
6class Database extends mysqli
7{
8 var $Prefix = '';
9
10 function select($Table, $What = '*', $Condition = 1)
11 {
12 $Query = "SELECT ".$What." FROM `".$this->Prefix.$Table."` WHERE ".$Condition;
13 return($this->query($Query));
14 }
15
16 function delete($Table, $Condition)
17 {
18 $this->query("DELETE FROM `".$this->Prefix.$Table."` WHERE ".$Condition);
19 }
20
21 function insert($Table, $Data)
22 {
23 $Name = '';
24 $Values = '';
25 foreach($Data as $Key => $Value)
26 {
27 $Value = strtr($Value, '"', '\"');
28 $Name .= ','.$Key;
29 if($Value == 'NOW()') $Values .= ",".$Value;
30 else $Values .= ",'".$Value."'";
31 }
32 $Name = substr($Name, 1);
33 $Values = substr($Values, 1);
34 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
35 }
36
37 function update($Table, $Condition, $Data)
38 {
39 $Values = '';
40 foreach($Data as $Key => $Value)
41 {
42 $Value = strtr($Value, '"', '\"');
43 if($Value != 'NOW()') $Value = "'".$Value."'";
44 $Values .= ", ".$Key."=".$Value;
45 }
46 $Values = substr($Values, 2);
47 $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
48 }
49
50 function replace($Table, $Data)
51 {
52 $Name = '';
53 $Values = '';
54 foreach($Data as $Key => $Value)
55 {
56 $Value = strtr($Value, '"', '\"');
57 $Name .= ',`'.$Key.'`';
58 if($Value == 'NOW()') $Values .= ",".$Value;
59 else $Values .= ',"'.$Value.'"';
60 }
61 $Name = substr($Name, 1);
62 $Values = substr($Values, 1);
63 //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br>');
64 $this->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
65 //echo($this->error().'<br>');
66 }
67
68 function charset($Charset)
69 {
70 $this->query('SET CHARACTER SET '.$Charset);
71 }
72
73}
74
75?>
Note: See TracBrowser for help on using the repository browser.