source: trunk/database.php

Last change on this file was 35, checked in by george, 16 years ago
  • Všechny soubory přesunuty do podsložky trunk.
File size: 3.9 KB
Line 
1<?php
2
3// Extended database class
4// Date: 2008-12-15
5
6class Database extends mysqli
7{
8 var $Prefix = '';
9 var $LastQuery = '';
10
11 function query($Query)
12 {
13 global $Config;
14
15 if($Config['Web']['ShowSQLQuery'] == true)
16 echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: silver; padding-bottom: 2px; padding-top: 2px; font-size: 12px; font-family: Arial;">'.$Query.'</div>');
17 $this->LastQuery = $Query;
18 $DbResult = parent::query($Query);
19 if(($this->error != '') and ($Config['Web']['ShowSQLError'] == true))
20 {
21 echo('<strong>Database error:</strong> '.$this->error.'<br />');
22 echo('<strong>Query:</strong> '.$Query.'<br />');
23 echo('<pre style="font-size: 9px">'); print_r(debug_backtrace()); echo('</pre>');
24 }
25 return($DbResult);
26 }
27
28 function select($Parameters) // Database, Table, Columns, Condition, Order
29 {
30 $Query = 'SELECT ';
31 if(array_key_exists('Columns', $Parameters)) $Query .= $Parameters['Columns']; else $Query .= '*';
32 $Query .= ' FROM ';
33 if(array_key_exists('Database', $Parameters) and ($Parameters['Database'] != '')) $Query .= '`'.$Parameters['Database'].'`.';
34 $Query .= '`'.$this->Prefix.$Parameters['Table'].'`';
35 if(array_key_exists('Condition', $Parameters)) $Query .= ' WHERE '.$Parameters['Condition'];
36 return($this->query($Query));
37 }
38
39 function delete($Parameters)
40 {
41 $Query = 'DELETE FROM ';
42 if(array_key_exists('Database', $Parameters) and ($Parameters['Database'] != '')) $Query .= '`'.$Parameters['Database'].'`.';
43 $Query .= '`'.$this->Prefix.$Parameters['Table'].'`';
44 if(array_key_exists('Condition', $Parameters)) $Query .= ' WHERE '.$Parameters['Condition'];
45 $this->query($Query);
46 }
47
48 function insert($Parameters, $Data)
49 {
50 $Name = '';
51 $Values = '';
52 foreach($Data as $Key => $Value)
53 {
54 $Value = strtr($Value, '"', '\"');
55 $Name .= ',`'.$Key.'`';
56 if($Value == 'NOW()') $Values .= ",".$Value;
57 else $Values .= ",'".$Value."'";
58 }
59 $Name = substr($Name, 1);
60 $Values = substr($Values, 1);
61 $Query = 'INSERT INTO ';
62 if(array_key_exists('Database', $Parameters) and ($Parameters['Database'] != '')) $Query .= '`'.$Parameters['Database'].'`.';
63 $Query .= '`'.$this->Prefix.$Parameters['Table'].'`';
64 $Query .= ' ('.$Name.') VALUES ('.$Values.')';
65 $this->query($Query);
66 }
67
68 function update($Parameters, $Data)
69 {
70 $Values = '';
71 foreach($Data as $Key => $Value)
72 {
73 $Value = strtr($Value, '"', '\"');
74 if($Value != 'NOW()') $Value = "'".$Value."'";
75 $Values .= ", `".$Key."`=".$Value;
76 }
77 $Values = substr($Values, 2);
78 $Query = 'UPDATE ';
79 if(array_key_exists('Database', $Parameters) and ($Parameters['Database'] != '')) $Query .= '`'.$Parameters['Database'].'`.';
80 $Query .= '`'.$this->Prefix.$Parameters['Table'].'`';
81 $Query .= ' SET '.$Values;
82 if(array_key_exists('Condition', $Parameters)) $Query .= ' WHERE '.$Parameters['Condition'];
83 $this->query($Query);
84 }
85
86 function replace($Parameters, $Data)
87 {
88 $Name = '';
89 $Values = '';
90 foreach($Data as $Key => $Value)
91 {
92 $Value = strtr($Value, '"', '\"');
93 $Name .= ',`'.$Key.'`';
94 if($Value == 'NOW()') $Values .= ",".$Value;
95 else $Values .= ',"'.$Value.'"';
96 }
97 $Name = substr($Name, 1);
98 $Values = substr($Values, 1);
99 //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br>');
100 $Query = 'REPLACE INTO ';
101 if(array_key_exists('Database', $Parameters) and ($Parameters['Database'] != '')) $Query .= '`'.$Parameters['Database'].'`.';
102 $Query .= '`'.$this->Prefix.$Parameters['Table'].'`';
103 $Query .= ' ('.$Name.') VALUES ('.$Values.')';
104 $this->query($Query);
105 }
106
107 function charset($Charset)
108 {
109 $this->query('SET CHARACTER SET '.$Charset);
110 }
111
112}
113
114?>
Note: See TracBrowser for help on using the repository browser.