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 | var $LastDataSet;
|
---|
11 | var $LastNumRows;
|
---|
12 | var $Debug = true;
|
---|
13 |
|
---|
14 | function query($Query)
|
---|
15 | {
|
---|
16 | $this->LastQuery = $Query;
|
---|
17 | if ($this->error <> '' and $this->Debug) $this->error.': '.$this->LastQuery;
|
---|
18 | return(parent::query($Query));
|
---|
19 | }
|
---|
20 |
|
---|
21 | function select($Table, $What = '*', $Condition = 1)
|
---|
22 | {
|
---|
23 | $this->LastQuery = "SELECT ".$What." FROM `".$this->Prefix.$Table."` WHERE ".$Condition;
|
---|
24 | $resul = $this->query($this->LastQuery);
|
---|
25 | if ($this->error <> '' and $this->Debug) echo $this->error.': '.$this->LastQuery;
|
---|
26 |
|
---|
27 | $this->LastNumRows = $resul->num_rows;
|
---|
28 | if ( $this->LastNumRows > 0 ) {
|
---|
29 | $this->LastDataSet = true;
|
---|
30 | } else {
|
---|
31 | $this->LastDataSet = false;
|
---|
32 | }
|
---|
33 | return($resul);
|
---|
34 | }
|
---|
35 |
|
---|
36 | function delete($Table, $Condition)
|
---|
37 | {
|
---|
38 | $this->LastQuery = "DELETE FROM `".$this->Prefix.$Table."` WHERE ".$Condition;
|
---|
39 | $this->query($this->LastQuery);
|
---|
40 | if ($this->error <> '' and $Debug) echo $this->error.': '.$this->LastQuery;
|
---|
41 | }
|
---|
42 |
|
---|
43 | function insert($Table, $Data)
|
---|
44 | {
|
---|
45 | $Name = '';
|
---|
46 | $Values = '';
|
---|
47 | foreach($Data as $Key => $Value)
|
---|
48 | {
|
---|
49 | $Value = strtr($Value, '"', '\"');
|
---|
50 | $Name .= ',`'.$Key.'`';
|
---|
51 | if($Value == 'NOW()') $Values .= ",".$Value;
|
---|
52 | else $Values .= ",'".$Value."'";
|
---|
53 | }
|
---|
54 | $Name = substr($Name, 1);
|
---|
55 | $Values = substr($Values, 1);
|
---|
56 | $this->LastQuery = 'INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')';
|
---|
57 | $this->query($this->LastQuery);
|
---|
58 | if ($this->error <> '' and $Debug) echo $this->error.': '.$this->LastQuery;
|
---|
59 | }
|
---|
60 |
|
---|
61 | function update($Table, $Condition, $Data)
|
---|
62 | {
|
---|
63 | $Values = '';
|
---|
64 | foreach($Data as $Key => $Value)
|
---|
65 | {
|
---|
66 | $Value = strtr($Value, '"', '\"');
|
---|
67 | if($Value != 'NOW()') $Value = "'".$Value."'";
|
---|
68 | $Values .= ", ".$Key."=".$Value;
|
---|
69 | }
|
---|
70 | $Values = substr($Values, 2);
|
---|
71 | $this->LastQuery = 'UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')';
|
---|
72 | $this->query($this->LastQuery);
|
---|
73 | if ($this->error <> '' and $this->Debug) echo $this->error.': '.$this->LastQuery;
|
---|
74 | }
|
---|
75 |
|
---|
76 | function replace($Table, $Data)
|
---|
77 | {
|
---|
78 | $Name = '';
|
---|
79 | $Values = '';
|
---|
80 | foreach($Data as $Key => $Value)
|
---|
81 | {
|
---|
82 | $Value = strtr($Value, '"', '\"');
|
---|
83 | $Name .= ',`'.$Key.'`';
|
---|
84 | if($Value == 'NOW()') $Values .= ",".$Value;
|
---|
85 | else $Values .= ',"'.$Value.'"';
|
---|
86 | }
|
---|
87 | $Name = substr($Name, 1);
|
---|
88 | $Values = substr($Values, 1);
|
---|
89 | //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br>');
|
---|
90 | $this->LastQuery = 'REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')';
|
---|
91 | $this->query($this->LastQuery);
|
---|
92 | //echo($this->error().'<br>');
|
---|
93 | }
|
---|
94 |
|
---|
95 | function charset($Charset)
|
---|
96 | {
|
---|
97 | $this->LastQuery = 'SET CHARACTER SET '.$Charset;
|
---|
98 | $this->query($this->LastQuery);
|
---|
99 | }
|
---|
100 |
|
---|
101 | }
|
---|
102 |
|
---|
103 | ?>
|
---|