Changeset 30 for database.php


Ignore:
Timestamp:
Dec 16, 2008, 8:15:34 AM (16 years ago)
Author:
george
Message:
  • Přidáno: Podpora pro určování v definicích krom tabulky také jméno databáze a jméno primárního identifikačního sloupce.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • database.php

    r24 r30  
    22
    33// Extended database class
    4 // Date: 2008-10-13
     4// Date: 2008-12-15
    55
    66class Database extends mysqli
     
    1616    if(($this->ShowError == TRUE) and ($this->error != ''))
    1717    {
    18       echo('<strong>Database error:</strong> '.$this->error.'<br /><strong>Query:</strong> '.$Query.'<br />');
     18      echo('<strong>Database error:</strong> '.$this->error.'<br />');
     19      echo('<strong>Query:</strong> '.$Query.'<br />');
    1920      echo('<pre style="font-size: 9px">'); print_r(debug_backtrace()); echo('</pre>');
    2021    }
     
    2223  }
    2324
    24   function select($Table, $What = '*', $Condition = 1)
     25  function select($Parameters) // Database, Table, Columns, Condition, Order
    2526  {
    26     return($this->query("SELECT ".$What." FROM `".$this->Prefix.$Table."` WHERE ".$Condition));
     27    $Query = 'SELECT ';
     28    if(array_key_exists('Columns', $Parameters)) $Query .= $Parameters['Columns']; else $Query .= '*';
     29    $Query .= ' FROM ';
     30    if(array_key_exists('Database', $Parameters) and ($Parameters['Database'] != '')) $Query .= '`'.$Parameters['Database'].'`.';
     31    $Query .= '`'.$this->Prefix.$Parameters['Table'].'`';
     32    if(array_key_exists('Condition', $Parameters)) $Query .= ' WHERE '.$Parameters['Condition'];
     33    return($this->query($Query));
    2734  }
    2835
    29   function delete($Table, $Condition)
     36  function delete($Parameters)
    3037  {
    31     $this->query("DELETE FROM `".$this->Prefix.$Table."` WHERE ".$Condition);
     38    $Query = 'DELETE FROM ';
     39    if(array_key_exists('Database', $Parameters) and ($Parameters['Database'] != '')) $Query .= '`'.$Parameters['Database'].'`.';
     40    $Query .= '`'.$this->Prefix.$Parameters['Table'].'`';
     41    if(array_key_exists('Condition', $Parameters)) $Query .= ' WHERE '.$Parameters['Condition'];
     42    $this->query($Query);
    3243  }
    3344
    34   function insert($Table, $Data)
     45  function insert($Parameters, $Data)
    3546  {
    3647    $Name = '';
     
    4556    $Name = substr($Name, 1);
    4657    $Values = substr($Values, 1);
    47     $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
     58    $Query = 'INSERT INTO ';
     59    if(array_key_exists('Database', $Parameters) and ($Parameters['Database'] != '')) $Query .= '`'.$Parameters['Database'].'`.';
     60    $Query .= '`'.$this->Prefix.$Parameters['Table'].'`';
     61    $Query .= ' ('.$Name.') VALUES ('.$Values.')';
     62    $this->query($Query);
    4863  }
    4964
    50   function update($Table, $Condition, $Data)
     65  function update($Parameters, $Data)
    5166  {
    5267    $Values = '';
     
    5873    }
    5974    $Values = substr($Values, 2);
    60     $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
     75    $Query = 'UPDATE ';
     76    if(array_key_exists('Database', $Parameters) and ($Parameters['Database'] != '')) $Query .= '`'.$Parameters['Database'].'`.';
     77    $Query .= '`'.$this->Prefix.$Parameters['Table'].'`';
     78    $Query .= ' SET '.$Values;
     79    if(array_key_exists('Condition', $Parameters)) $Query .= ' WHERE '.$Parameters['Condition'];
     80    $this->query($Query);
    6181  }
    6282
    63   function replace($Table, $Data)
     83  function replace($Parameters, $Data)
    6484  {
    6585    $Name = '';
     
    7595    $Values = substr($Values, 1);
    7696    //echo('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES ('.$Values.')<br>');
    77     $this->query('REPLACE INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
     97    $Query = 'REPLACE INTO ';
     98    if(array_key_exists('Database', $Parameters) and ($Parameters['Database'] != '')) $Query .= '`'.$Parameters['Database'].'`.';
     99    $Query .= '`'.$this->Prefix.$Parameters['Table'].'`';
     100    $Query .= ' ('.$Name.') VALUES ('.$Values.')';
     101    $this->query($Query);
    78102  }
    79103
Note: See TracChangeset for help on using the changeset viewer.