source: devel/www/database.php@ 90

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

Přidáno: Nová vývojová větev webu sítě. Všechny stránky jsou předělávány na objektový přístup a stránky samotné nevypisují výstup přímo přes echo, ale vracejí zobrazovaná data přes návratovou hodnotu funkce.

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