source: trunk/includes/Database.php@ 477

Last change on this file since 477 was 457, checked in by george, 15 years ago
  • Opraveno: Zbylé použití procedurálních funkcí mysql_ přepsáno na objektové.
File size: 2.9 KB
Line 
1<?php
2
3// Extended database class
4// Date: 2010-01-29
5
6class Database extends mysqli
7{
8 var $HostName = 'localhost';
9 var $UserName;
10 var $Password;
11 var $Schema;
12 var $Charset = 'utf8';
13 var $Prefix = '';
14 var $ShowSQLQuery = false;
15 var $ShowSQLError = false;
16
17 function open()
18 {
19 parent::connect($this->HostName, $this->UserName, $this->Password, $this->Schema);
20 $this->charset($this->Charset);
21 }
22
23 function query($Query)
24 {
25
26 if($this->ShowSQLQuery)
27 {
28 if(isset($_SERVER['REMOTE_ADDR'])) 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>');
29 else echo($Query."\n");
30 }
31 $Result = parent::query($Query);
32 if(($this->error != '') and ($this->ShowSQLError))
33 {
34 if(isset($_SERVER['REMOTE_ADDR'])) echo('<div><strong>SQL Error: </strong>'.$this->error.'<br />'.$Query.'</div>');
35 echo('SQL Error: '.$this->error.' '.$Query."\n");
36 }
37
38 return($Result);
39 }
40
41 function select($Table, $What = '*', $Condition = 1)
42 {
43 return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition));
44 }
45
46 function delete($Table, $Condition)
47 {
48 $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition);
49 }
50
51 function insert($Table, $Data)
52 {
53 $Name = '';
54 $Values = '';
55 foreach($Data as $Key => $Value)
56 {
57 $Name .= ',`'.$Key.'`';
58 $Values .= ','.$Value;
59 }
60 $Name = substr($Name, 1);
61 $Values = substr($Values, 1);
62 $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
63 }
64
65 function update($Table, $Condition, $Data)
66 {
67 $Values = '';
68 foreach($Data as $Key => $Value)
69 {
70 $Values .= ', `'.$Key.'`='.$Value;
71 }
72 $Values = substr($Values, 2);
73 $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
74 }
75
76 function replace($Table, $Data)
77 {
78 $Name = '';
79 $Values = '';
80 foreach($Data as $Key => $Value)
81 {
82 $Name .= ',`'.$Key.'`';
83 $Values .= ','.$Value;
84 }
85 $Name = substr($Name, 1);
86 $Values = substr($Values, 1);
87 //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br />');
88 $this->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
89 //echo($this->error().'<br>');
90 }
91
92 function charset($Charset)
93 {
94 $this->query('SET NAMES "'.$Charset.'"');
95 }
96
97 function TimeToMysqlDateTime($Time)
98 {
99 return(date('Y-m-d H:i:s', $Time));
100 }
101
102 function MysqlDateTimeToTime($Time)
103 {
104 $Parts = explode(' ', $Time);
105 $DateParts = explode('-', $Parts[0]);
106 $TimeParts = explode(':', $Parts[1]);
107 $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]);
108 return($Result);
109 }
110
111 function MysqlDateToTime($Time)
112 {
113 return($this->MysqlDateTimeToTime($Time.' 0:0:0'));
114 }
115}
116
117?>
Note: See TracBrowser for help on using the repository browser.