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