Ignore:
Timestamp:
Apr 14, 2020, 11:13:32 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
File:
1 edited

Legend:

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

    r1 r7  
    1111  function fetch_assoc()
    1212  {
    13     return($this->PDOStatement->fetch(PDO::FETCH_ASSOC));
     13    return $this->PDOStatement->fetch(PDO::FETCH_ASSOC);
    1414  }
    1515
    1616  function fetch_array()
    1717  {
    18     return($this->PDOStatement->fetch(PDO::FETCH_BOTH));
     18    return $this->PDOStatement->fetch(PDO::FETCH_BOTH);
    1919  }
    2020
    2121  function fetch_row()
    2222  {
    23     return($this->PDOStatement->fetch(PDO::FETCH_NUM));
     23    return $this->PDOStatement->fetch(PDO::FETCH_NUM);
    2424  }
    2525}
     
    5454  function Connect($Host, $User, $Password, $Database)
    5555  {
    56     if($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;
    57       else if($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host;
     56    if ($this->Type == 'mysql') $ConnectionString = 'mysql:host='.$Host.';dbname='.$Database;
     57      else if ($this->Type == 'pgsql') $ConnectionString = 'pgsql:dbname='.$Database.';host='.$Host;
    5858      else $ConnectionString = '';
    5959    try {
     
    7474  function Connected()
    7575  {
    76     return(isset($this->PDO));
     76    return isset($this->PDO);
    7777  }
    7878
     
    8484  function query($Query)
    8585  {
    86     if(!$this->Connected()) throw new Exception(T('Not connected to database'));
    87     if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime();
     86    if (!$this->Connected()) throw new Exception(T('Not connected to database'));
     87    if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true)) $QueryStartTime = microtime();
    8888    $this->LastQuery = $Query;
    89     if(($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))
     89    if (($this->ShowSQLQuery == true) or ($this->LogSQLQuery == true))
    9090      $Duration = ' ; '.round(microtime() - $QueryStartTime, 4). ' s';
    91     if($this->LogSQLQuery == true)
     91    if ($this->LogSQLQuery == true)
    9292      file_put_contents($this->LogFile, $Query.$Duration."\n", FILE_APPEND);
    93     if($this->ShowSQLQuery == true)
     93    if ($this->ShowSQLQuery == true)
    9494      echo('<div style="border-bottom-width: 1px; border-bottom-style: solid; '.
    9595      'padding-bottom: 3px; padding-top: 3px; font-size: 12px; font-family: Arial;">'.$Query.$Duration.'</div>'."\n");
    9696    $Result = new DatabaseResult();
    9797    $Result->PDOStatement = $this->PDO->query($Query);
    98     if($Result->PDOStatement)
     98    if ($Result->PDOStatement)
    9999    {
    100100      $Result->num_rows = $Result->PDOStatement->rowCount();
     
    104104      $this->Error = $this->PDO->errorInfo();
    105105      $this->Error = $this->Error[2];
    106       if(($this->Error != '') and ($this->ShowSQLError == true))
     106      if (($this->Error != '') and ($this->ShowSQLError == true))
    107107        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
    108108        throw new Exception('SQL Error: '.$this->Error.', Query: '.$Query);
    109109    }
    110     return($Result);
     110    return $Result;
    111111  }
    112112
    113113  function select($Table, $What = '*', $Condition = 1)
    114114  {
    115     return($this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition));
     115    return $this->query('SELECT '.$What.' FROM `'.$this->Prefix.$Table.'` WHERE '.$Condition);
    116116  }
    117117
     
    125125    $Name = '';
    126126    $Values = '';
    127     foreach($Data as $Key => $Value)
     127    foreach ($Data as $Key => $Value)
    128128    {
    129129      $Name .= ',`'.$Key.'`';
    130       if(!in_array($Value, $this->Functions))
     130      if (!in_array($Value, $this->Functions))
    131131      {
    132         if(is_null($Value)) $Value = 'NULL';
     132        if (is_null($Value)) $Value = 'NULL';
    133133        else $Value = $this->PDO->quote($Value);
    134134      }
     
    144144  {
    145145    $Values = '';
    146     foreach($Data as $Key => $Value)
    147     {
    148       if(!in_array($Value, $this->Functions))
     146    foreach ($Data as $Key => $Value)
     147    {
     148      if (!in_array($Value, $this->Functions))
    149149      {
    150         if(is_null($Value)) $Value = 'NULL';
     150        if (is_null($Value)) $Value = 'NULL';
    151151        else $Value = $this->PDO->quote($Value);
    152152      }
     
    161161    $Name = '';
    162162    $Values = '';
    163     foreach($Data as $Key => $Value)
    164     {
    165       if(!in_array($Value, $this->Functions))
     163    foreach ($Data as $Key => $Value)
     164    {
     165      if (!in_array($Value, $this->Functions))
    166166      {
    167         if(is_null($Value)) $Value = 'NULL';
     167        if (is_null($Value)) $Value = 'NULL';
    168168        else $Value = $this->PDO->quote($Value);
    169169      }
     
    185185  function real_escape_string($Text)
    186186  {
    187     return(addslashes($Text));
     187    return addslashes($Text);
    188188  }
    189189
    190190  function quote($Text)
    191191  {
    192     return($this->PDO->quote($Text));
     192    return $this->PDO->quote($Text);
    193193  }
    194194
     
    205205function TimeToMysqlDateTime($Time)
    206206{
    207   if($Time == NULL) return(NULL);
    208     else return(date('Y-m-d H:i:s', $Time));
     207  if ($Time == NULL) return NULL;
     208    else return date('Y-m-d H:i:s', $Time);
    209209}
    210210
    211211function TimeToMysqlDate($Time)
    212212{
    213   if($Time == NULL) return(NULL);
    214     else return(date('Y-m-d', $Time));
     213  if ($Time == NULL) return NULL;
     214    else return date('Y-m-d', $Time);
    215215}
    216216
    217217function TimeToMysqlTime($Time)
    218218{
    219   if($Time == NULL) return(NULL);
    220     else return(date('H:i:s', $Time));
     219  if ($Time == NULL) return NULL;
     220    else return date('H:i:s', $Time);
    221221}
    222222
    223223function MysqlDateTimeToTime($DateTime)
    224224{
    225   if($DateTime == '') return(NULL);
     225  if ($DateTime == '') return NULL;
    226226  $Parts = explode(' ', $DateTime);
    227227  $DateParts = explode('-', $Parts[0]);
    228228  $TimeParts = explode(':', $Parts[1]);
    229229  $Result = mktime($TimeParts[0], $TimeParts[1], $TimeParts[2], $DateParts[1], $DateParts[2], $DateParts[0]);
    230   return($Result);
     230  return $Result;
    231231}
    232232
    233233function MysqlDateToTime($Date)
    234234{
    235   if($Date == '') return(NULL);
    236   return(MysqlDateTimeToTime($Date.' 0:0:0'));
     235  if ($Date == '') return NULL;
     236  return MysqlDateTimeToTime($Date.' 0:0:0');
    237237}
    238238
    239239function MysqlTimeToTime($Time)
    240240{
    241   if($Time == '') return(NULL);
    242   return(MysqlDateTimeToTime('0000-00-00 '.$Time));
    243 }
     241  if ($Time == '') return NULL;
     242  return MysqlDateTimeToTime('0000-00-00 '.$Time);
     243}
Note: See TracChangeset for help on using the changeset viewer.