1 | <?php
|
---|
2 |
|
---|
3 | // Extended database class
|
---|
4 | // Date: 2007-07-19
|
---|
5 |
|
---|
6 | class 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 | function replace($Table, $Data)
|
---|
50 | {
|
---|
51 | $Name = '';
|
---|
52 | $Values = '';
|
---|
53 | foreach($Data as $Key => $Value)
|
---|
54 | {
|
---|
55 | $Value = strtr($Value, '"', '\"');
|
---|
56 | $Name .= ",".$Key;
|
---|
57 | if($Value == 'NOW()') $Values .= ",".$Value;
|
---|
58 | else $Values .= ',"'.$Value.'"';
|
---|
59 | }
|
---|
60 | $Name = substr($Name, 1);
|
---|
61 | $Values = substr($Values, 1);
|
---|
62 | $this->query('REPLACE INTO `'.$this->Prefix.$Table.'` (`'.$Name.'`) VALUES('.$values.')');
|
---|
63 | }
|
---|
64 |
|
---|
65 | function charset($Charset)
|
---|
66 | {
|
---|
67 | $this->query('SET CHARACTER SET '.$Charset);
|
---|
68 | }
|
---|
69 |
|
---|
70 | }
|
---|
71 |
|
---|
72 | ?>
|
---|