Ignore:
Timestamp:
May 29, 2014, 11:59:39 PM (10 years ago)
Author:
chronos
Message:
  • Opraveno: Zobrazení hodnoty času trvání změn stavu rozhraní.
  • Upraveno: Vzdálenou IP klienta nezjišťovat z proxy adres. Tyto adresy se dají falšovat a tedy nejsou spolehlivé.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/Database.php

    r634 r659  
    88  var $PDOStatement;
    99  var $num_rows = 0;
    10  
     10
    1111  function fetch_assoc()
    1212  {
    1313    return($this->PDOStatement->fetch(PDO::FETCH_ASSOC));
    1414  }
    15  
     15
    1616  function fetch_array()
    1717  {
     
    3636  var $ShowSQLError;
    3737  var $ShowSQLQuery;
    38  
     38
    3939  function __construct()
    40   { 
     40  {
    4141    $this->Type = 'mysql';  // mysql, pgsql
    4242    $this->ShowSQLError = false;
     
    4444    $this->Functions = array('NOW()', 'CURDATE()', 'CURTIME()', 'UUID()');
    4545  }
    46  
     46
    4747  function Connect($Host, $User, $Password, $Database)
    48   {   
     48  {
    4949    if($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;
    5050      else if($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host;
     
    5959    }
    6060  }
    61  
     61
    6262  function Disconnect()
    6363  {
    6464    unset($this->PDO);
    6565  }
    66  
     66
    6767  function Connected()
    6868  {
    6969    return(isset($this->PDO));
    7070  }
    71  
     71
    7272  function select_db($Database)
    7373  {
    7474    $this->query('USE `'.$Database.'`');
    7575  }
    76  
     76
    7777  function query($Query)
    7878  {
    7979    if(!$this->Connected()) throw new Exception('Not connected to database');
    8080    $this->LastQuery = $Query;
    81     if($this->ShowSQLQuery == true) 
     81    if($this->ShowSQLQuery == true)
    8282      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>'."\n");
    8383    $Result = new DatabaseResult();
     
    9191      $this->Error = $this->PDO->errorInfo();
    9292      $this->Error = $this->Error[2];
    93       if(($this->Error != '') and ($this->ShowSQLError == true)) 
     93      if(($this->Error != '') and ($this->ShowSQLError == true))
    9494        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
    9595        throw new Exception('SQL Error: '.$this->Error.', Query: '.$Query);
    9696    }
    97     return($Result); 
     97    return($Result);
    9898  }
    9999
    100100  function select($Table, $What = '*', $Condition = 1)
    101   {   
    102     return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition)); 
     101  {
     102    return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition));
    103103  }
    104104
    105105  function delete($Table, $Condition)
    106106  {
    107     $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition); 
    108   }
    109  
     107    $this->query('DELETE FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition);
     108  }
     109
    110110  function insert($Table, $Data)
    111111  {
     
    115115    {
    116116      $Name .= ',`'.$Key.'`';
    117       if(!in_array($Value, $this->Functions)) 
     117      if(!in_array($Value, $this->Functions))
    118118      {
    119119        if(is_null($Value)) $Value = 'NULL';
     
    124124    $Name = substr($Name, 1);
    125125    $Values = substr($Values, 1);
    126     $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')'); 
     126    $this->query('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
    127127    $this->insert_id = $this->PDO->lastInsertId();
    128128  }
    129  
     129
    130130  function update($Table, $Condition, $Data)
    131131  {
     
    133133    foreach($Data as $Key => $Value)
    134134    {
    135       if(!in_array($Value, $this->Functions)) 
     135      if(!in_array($Value, $this->Functions))
    136136      {
    137137        if(is_null($Value)) $Value = 'NULL';
     
    140140      $Values .= ', `'.$Key.'`='.$Value;
    141141    }
    142     $Values = substr($Values, 2); 
     142    $Values = substr($Values, 2);
    143143    $this->query('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
    144144  }
    145  
     145
    146146  function replace($Table, $Data)
    147147  {
     
    150150    foreach($Data as $Key => $Value)
    151151    {
    152       if(!in_array($Value, $this->Functions)) 
     152      if(!in_array($Value, $this->Functions))
    153153      {
    154154        if(is_null($Value)) $Value = 'NULL';
     
    164164    //echo($this->error().'<br>');
    165165  }
    166  
     166
    167167  function charset($Charset)
    168168  {
    169169    $this->query('SET NAMES "'.$Charset.'"');
    170170  }
    171  
     171
    172172  function real_escape_string($Text)
    173173  {
    174174    return(addslashes($Text));
    175175  }
    176  
     176
    177177  public function __sleep()
    178178  {
     
    188188{
    189189  if($Time == NULL) return(NULL);
    190     else return(date('Y-m-d H:i:s', $Time)); 
     190    else return(date('Y-m-d H:i:s', $Time));
    191191}
    192192
     
    194194{
    195195  if($Time == NULL) return(NULL);
    196     else return(date('Y-m-d', $Time)); 
     196    else return(date('Y-m-d', $Time));
    197197}
    198198
     
    200200{
    201201  if($Time == NULL) return(NULL);
    202     else return(date('H:i:s', $Time)); 
     202    else return(date('H:i:s', $Time));
    203203}
    204204
    205205function MysqlDateTimeToTime($DateTime)
    206206{
    207   if($DateTime == '') return(NULL);     
     207  if($DateTime == '') return(NULL);
    208208  $Parts = explode(' ', $DateTime);
    209   $DateParts = explode('-', $Parts[0]); 
     209  $DateParts = explode('-', $Parts[0]);
    210210  $TimeParts = explode(':', $Parts[1]);
    211   $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]); 
    212   return($Result); 
     211  $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]);
     212  return($Result);
    213213}
    214214
     
    216216{
    217217  if($Date == '') return(NULL);
    218   return(MysqlDateTimeToTime($Date.' 0:0:0')); 
     218  return(MysqlDateTimeToTime($Date.' 0:0:0'));
    219219}
    220220
     
    222222{
    223223  if($Time == '') return(NULL);
    224   return(MysqlDateTimeToTime('0000-00-00 '.$Time)); 
    225 }
     224  return(MysqlDateTimeToTime('0000-00-00 '.$Time));
     225}
Note: See TracChangeset for help on using the changeset viewer.