Changeset 342 for trunk/database.php


Ignore:
Timestamp:
Jan 17, 2012, 10:37:59 AM (13 years ago)
Author:
chronos
Message:
  • Upraveno: Databáze nyní hlásí chyby dotazů přes výjimky.
  • Opraveno: Inicializace modulů.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/database.php

    r336 r342  
    4444      else $ConnectionString = '';
    4545    $this->PDO = new PDO($ConnectionString, $User, $Password);
     46    $this->PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    4647  }
    4748 
     
    5354  function query($Query)
    5455  {
    55     $this->LastQuery = $Query;
    56     if($this->ShowSQLQuery == true)
    57       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");
    58     $Result = new DatabaseResult();
    59     $Result->PDOStatement = $this->PDO->query($Query);
    60     if($Result->PDOStatement)
     56    try
    6157    {
    62       $Result->num_rows = $Result->PDOStatement->rowCount();
    63     } else
     58      $this->LastQuery = $Query;
     59      if($this->ShowSQLQuery == true)
     60        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");
     61      $Result = new DatabaseResult();
     62      $Result->PDOStatement = $this->PDO->query($Query);
     63      if($Result->PDOStatement)
     64        $Result->num_rows = $Result->PDOStatement->rowCount();
     65    } catch(PDOException $E)
    6466    {
    65       $this->Error = $this->PDO->errorInfo();
    66       $this->Error = $this->Error[2];
     67      $this->Error = $E->getMessage();
    6768      if(($this->Error != '') and ($this->ShowSQLError == true))
    6869        echo('<div><strong>SQL Error: </strong>'.$this->Error.'<br />'.$Query.'</div>');
     
    115116    foreach($Data as $Key => $Value)
    116117    {
    117             if(!in_array($Value, $this->Functions)) $Value = $this->PDO->quote($Value);
     118      if(!in_array($Value, $this->Functions)) $Value = $this->PDO->quote($Value);
    118119      $Name .= ',`'.$Key.'`';
    119120      $Values .= ','.$Value;
Note: See TracChangeset for help on using the changeset viewer.