Exemplo n.º 1
0
Arquivo: rb.php Projeto: WTer/NJB
 /**
  * This method runs the actual SQL query and binds a list of parameters to the query.
  * slots. The result of the query will be stored in the protected property
  * $rs (always array). The number of rows affected (result of rowcount, if supported by database)
  * is stored in protected property $affectedRows. If the debug flag is set
  * this function will send debugging output to screen buffer.
  *
  * @param string $sql      the SQL string to be send to database server
  * @param array  $bindings the values that need to get bound to the query slots
  *
  * @return void
  */
 protected function runQuery($sql, $bindings, $options = array())
 {
     $this->connect();
     if ($this->loggingEnabled && $this->logger) {
         $this->logger->log($sql, $bindings);
     }
     try {
         if (strpos('pgsql', $this->dsn) === 0) {
             if (defined('\\PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT')) {
                 $statement = $this->pdo->prepare($sql, array(\PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => TRUE));
             } else {
                 $statement = $this->pdo->prepare($sql);
             }
         } else {
             $statement = $this->pdo->prepare($sql);
         }
         $this->bindParams($statement, $bindings);
         $statement->execute();
         $this->queryCounter++;
         $this->affectedRows = $statement->rowCount();
         if ($statement->columnCount()) {
             $fetchStyle = isset($options['fetchStyle']) ? $options['fetchStyle'] : NULL;
             if (isset($options['noFetch']) && $options['noFetch']) {
                 $this->resultArray = array();
                 return $statement;
             }
             $this->resultArray = $statement->fetchAll($fetchStyle);
             if ($this->loggingEnabled && $this->logger) {
                 $this->logger->log('resultset: ' . count($this->resultArray) . ' rows');
             }
         } else {
             $this->resultArray = array();
         }
     } catch (\PDOException $e) {
         //Unfortunately the code field is supposed to be int by default (php)
         //So we need a property to convey the SQL State code.
         $err = $e->getMessage();
         if ($this->loggingEnabled && $this->logger) {
             $this->logger->log('An error occurred: ' . $err);
         }
         $exception = new SQL($err, 0);
         $exception->setSQLState($e->getCode());
         throw $exception;
     }
 }
Exemplo n.º 2
0
 public function get($sql, $values = array())
 {
     $exception = new SQL('Just a trouble maker');
     $exception->setSQLState($this->sqlState);
     throw $exception;
 }