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