Advertisement
natsume

Flux Connection Statement patch #1

Sep 19th, 2013
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2. require_once 'Flux/LogFile.php';
  3. require_once 'Flux/Error.php';
  4.  
  5. class Flux_Connection_Statement {
  6.     public $stmt;
  7.     private static $errorLog;
  8.    
  9.     public function __construct(PDOStatement $stmt)
  10.     {
  11.         $this->stmt = $stmt;
  12.         date_default_timezone_set('Your timezone'); //to get rid of the httpd error
  13.        
  14.         if (!self::$errorLog) {
  15.             self::$errorLog = new Flux_LogFile(FLUX_DATA_DIR.'/logs/mysql/errors/'.date('Ymd').'.log', 'a');
  16.         }
  17.     }
  18.    
  19.     public function execute(array $inputParameters = array())
  20.     {
  21.         $res = $this->stmt->execute($inputParameters);
  22.         Flux::$numberOfQueries++;
  23.         if ((int)$this->stmt->errorCode()) {
  24.             $info = $this->stmt->errorInfo();
  25.             self::$errorLog->puts('[SQLSTATE=%s] Err %s: %s', $info[0], $info[1], $info[2]);
  26.             if (Flux::config('DebugMode')) {
  27.                 $message = sprintf('MySQL error (SQLSTATE: %s, ERROR: %s): %s', $info[0], $info[1], $info[2]);
  28.                 throw new Flux_Error($message);
  29.             }
  30.         }
  31.         return $res;
  32.     }
  33.    
  34.     public function __call($method, $args)
  35.     {
  36.         return call_user_func_array(array($this->stmt, $method), $args);
  37.     }
  38. }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement