1 | <?php
|
---|
2 |
|
---|
3 | // Extended database class
|
---|
4 | // Date: 2009-02-16
|
---|
5 |
|
---|
6 |
|
---|
7 | class Database extends mysqli
|
---|
8 | {
|
---|
9 | var $Prefix = '';
|
---|
10 | var $Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()');
|
---|
11 |
|
---|
12 | function query($Query)
|
---|
13 | {
|
---|
14 | global $Config;
|
---|
15 |
|
---|
16 | if($Config['Web']['ShowSQLQuery'] == true)
|
---|
17 | echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.'</div>');
|
---|
18 | $Result = parent::query($Query);
|
---|
19 | if(($this->error != '') and ($Config['Web']['ShowSQLError'] == true))
|
---|
20 | echo('<div><strong>SQL Error: </strong>'.$this->error.'<br />'.$Query.'</div>');
|
---|
21 |
|
---|
22 | return($Result);
|
---|
23 | }
|
---|
24 |
|
---|
25 | function select($Table, $What = '*', $Condition = 1)
|
---|
26 | {
|
---|
27 | return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition));
|
---|
28 | }
|
---|
29 |
|
---|
30 | function delete($Table, $Condition)
|
---|
31 | {
|
---|
32 | $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition);
|
---|
33 | }
|
---|
34 |
|
---|
35 | function insert($Table, $Data)
|
---|
36 | {
|
---|
37 | $Name = '';
|
---|
38 | $Values = '';
|
---|
39 | foreach($Data as $Key => $Value)
|
---|
40 | {
|
---|
41 | $Name .= ',`'.$Key.'`';
|
---|
42 | if(!in_array($Value, $this->Functions)) $Value = '"'.$this->real_escape_string($Value).'"';
|
---|
43 | $Values .= ','.$Value;
|
---|
44 | }
|
---|
45 | $Name = substr($Name, 1);
|
---|
46 | $Values = substr($Values, 1);
|
---|
47 | $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
|
---|
48 | }
|
---|
49 |
|
---|
50 | function update($Table, $Condition, $Data)
|
---|
51 | {
|
---|
52 | $Values = '';
|
---|
53 | foreach($Data as $Key => $Value)
|
---|
54 | {
|
---|
55 | if(!in_array($Value, $this->Functions)) $Value = '"'.$this->real_escape_string($Value).'"';
|
---|
56 | $Values .= ', '.$Key.'='.$Value;
|
---|
57 | }
|
---|
58 | $Values = substr($Values, 2);
|
---|
59 | $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
|
---|
60 | }
|
---|
61 |
|
---|
62 | function replace($Table, $Data)
|
---|
63 | {
|
---|
64 | $Name = '';
|
---|
65 | $Values = '';
|
---|
66 | foreach($Data as $Key => $Value)
|
---|
67 | {
|
---|
68 | if(!in_array($Value, $this->Functions)) $Value = '"'.$this->real_escape_string($Value).'"';
|
---|
69 | $Name .= ',`'.$Key.'`';
|
---|
70 | $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->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
|
---|
76 | //echo($this->error().'<br>');
|
---|
77 | }
|
---|
78 |
|
---|
79 | function charset($Charset)
|
---|
80 | {
|
---|
81 | $this->query('SET NAMES "'.$Charset.'"');
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | ?>
|
---|