Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Database.php

    r861 r873  
    1717  function fetch_assoc()
    1818  {
    19     return($this->PDOStatement->fetch(PDO::FETCH_ASSOC));
     19    return ($this->PDOStatement->fetch(PDO::FETCH_ASSOC));
    2020  }
    2121
    2222  function fetch_array()
    2323  {
    24     return($this->PDOStatement->fetch(PDO::FETCH_BOTH));
     24    return ($this->PDOStatement->fetch(PDO::FETCH_BOTH));
    2525  }
    2626
    2727  function fetch_row()
    2828  {
    29     return($this->PDOStatement->fetch(PDO::FETCH_NUM));
     29    return ($this->PDOStatement->fetch(PDO::FETCH_NUM));
    3030  }
    3131}
     
    6161  function Connect($Host, $User, $Password, $Database)
    6262  {
    63     if($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;
    64       else if($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host;
     63    if ($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;
     64      else if ($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host;
    6565      else $ConnectionString = '';
    6666    try {
     
    8181  function Connected()
    8282  {
    83     return(isset($this->PDO));
     83    return (isset($this->PDO));
    8484  }
    8585
     
    9191  function query($Query)
    9292  {
    93     if(!$this->Connected()) throw new Exception(T('Not connected to database'));
    94     if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float();
     93    if (!$this->Connected()) throw new Exception(T('Not connected to database'));
     94    if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime_float();
    9595    $this->LastQuery = $Query;
    9696    //echo('a'.$this->ShowSQLQuery.'<'.$QueryStartTime.', '.microtime_float());
    97     if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))
     97    if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))
    9898    {
    9999      $Time = round(microtime_float() - $QueryStartTime, 4);
    100100      $Duration = ' ; '.$Time. ' s';
    101101    }
    102     if(($this->LogSQLQuery == true) and ($Time != 0))
     102    if (($this->LogSQLQuery == true) and ($Time != 0))
    103103      file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
    104     if($this->ShowSQLQuery == true)
     104    if ($this->ShowSQLQuery == true)
    105105      echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; '.
    106106      'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n");
    107107    $Result = new DatabaseResult();
    108108    $Result->PDOStatement = $this->PDO->query($Query);
    109     if($Result->PDOStatement)
     109    if ($Result->PDOStatement)
    110110    {
    111111      $Result->num_rows = $Result->PDOStatement->rowCount();
     
    115115      $this->Error = $this->PDO->errorInfo();
    116116      $this->Error = $this->Error[2];
    117       if(($this->Error != '') and ($this->ShowSQLError == true))
     117      if (($this->Error != '') and ($this->ShowSQLError == true))
    118118        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
    119119        throw new Exception('SQL Error: '.$this->Error.', Query: '.$Query);
    120120    }
    121     return($Result);
     121    return ($Result);
    122122  }
    123123
    124124  function select($Table, $What = '*', $Condition = 1)
    125125  {
    126     return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition));
     126    return ($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition));
    127127  }
    128128
     
    142142    $Name = '';
    143143    $Values = '';
    144     foreach($Data as $Key => $Value)
     144    foreach ($Data as $Key => $Value)
    145145    {
    146146      $Name .= ',`'.$Key.'`';
    147       if(!in_array($Value, $this->Functions))
     147      if (!in_array($Value, $this->Functions))
    148148      {
    149         if(is_null($Value)) $Value = 'NULL';
     149        if (is_null($Value)) $Value = 'NULL';
    150150        else $Value = $this->PDO->quote($Value);
    151151      }
     
    154154    $Name = substr($Name, 1);
    155155    $Values = substr($Values, 1);
    156     return('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
     156    return ('INSERT INTO `'.$this->Prefix.$Table.'` ('.$Name.') VALUES('.$Values.')');
    157157  }
    158158
     
    165165  {
    166166    $Values = '';
    167     foreach($Data as $Key => $Value)
    168     {
    169       if(!in_array($Value, $this->Functions))
     167    foreach ($Data as $Key => $Value)
     168    {
     169      if (!in_array($Value, $this->Functions))
    170170      {
    171         if(is_null($Value)) $Value = 'NULL';
     171        if (is_null($Value)) $Value = 'NULL';
    172172        else $Value = $this->PDO->quote($Value);
    173173      }
     
    175175    }
    176176    $Values = substr($Values, 2);
    177     return('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
     177    return ('UPDATE `'.$this->Prefix.$Table.'` SET '.$Values.' WHERE ('.$Condition.')');
    178178  }
    179179
     
    182182    $Name = '';
    183183    $Values = '';
    184     foreach($Data as $Key => $Value)
    185     {
    186       if(!in_array($Value, $this->Functions))
     184    foreach ($Data as $Key => $Value)
     185    {
     186      if (!in_array($Value, $this->Functions))
    187187      {
    188         if(is_null($Value)) $Value = 'NULL';
     188        if (is_null($Value)) $Value = 'NULL';
    189189        else $Value = $this->PDO->quote($Value);
    190190      }
     
    206206  function real_escape_string($Text)
    207207  {
    208     return(addslashes($Text));
     208    return (addslashes($Text));
    209209  }
    210210
    211211  function quote($Text)
    212212  {
    213     return($this->PDO->quote($Text));
     213    return ($this->PDO->quote($Text));
    214214  }
    215215
     
    239239function TimeToMysqlDateTime($Time)
    240240{
    241   if($Time == NULL) return(NULL);
    242     else return(date('Y-m-d H:i:s', $Time));
     241  if ($Time == NULL) return (NULL);
     242    else return (date('Y-m-d H:i:s', $Time));
    243243}
    244244
    245245function TimeToMysqlDate($Time)
    246246{
    247   if($Time == NULL) return(NULL);
    248     else return(date('Y-m-d', $Time));
     247  if ($Time == NULL) return (NULL);
     248    else return (date('Y-m-d', $Time));
    249249}
    250250
    251251function TimeToMysqlTime($Time)
    252252{
    253   if($Time == NULL) return(NULL);
    254     else return(date('H:i:s', $Time));
     253  if ($Time == NULL) return (NULL);
     254    else return (date('H:i:s', $Time));
    255255}
    256256
    257257function MysqlDateTimeToTime($DateTime)
    258258{
    259   if($DateTime == '') return(NULL);
     259  if ($DateTime == '') return (NULL);
    260260  $Parts = explode(' ', $DateTime);
    261261  $DateParts = explode('-', $Parts[0]);
    262262  $TimeParts = explode(':', $Parts[1]);
    263263  $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]);
    264   return($Result);
     264  return ($Result);
    265265}
    266266
    267267function MysqlDateToTime($Date)
    268268{
    269   if($Date == '') return(NULL);
    270   return(MysqlDateTimeToTime($Date.' 0:0:0'));
     269  if ($Date == '') return (NULL);
     270  return (MysqlDateTimeToTime($Date.' 0:0:0'));
    271271}
    272272
    273273function MysqlTimeToTime($Time)
    274274{
    275   if($Time == '') return(NULL);
    276   return(MysqlDateTimeToTime('0000-00-00 '.$Time));
    277 }
     275  if ($Time == '') return (NULL);
     276  return (MysqlDateTimeToTime('0000-00-00 '.$Time));
     277}
Note: See TracChangeset for help on using the changeset viewer.