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