Ejemplo n.º 1
0
 /**
  * Execute a raw SQL query on the database
  * @param string $sql    SQL query string
  * @param array  $values Optional values array to bind in query
  * @return mixed A result set object
  */
 public function Query($sql, &$values = array())
 {
     // Log it
     if (count($values) > 0) {
         ChickenWire::Log($sql . " ==> " . implode(", ", $values), "SQL Query");
     } else {
         ChickenWire::Log($sql, "SQL Query");
     }
     // Store query
     $this->lastQuery = $sql;
     // Try to prepare the query
     try {
         if (!($sth = $this->pdo->prepare($sql))) {
             throw new DBException($this);
         }
     } catch (PDOException $e) {
         throw new DBException($this);
     }
     // Set fetch mode
     $sth->setFetchMode(PDO::FETCH_ASSOC);
     // Execute query
     try {
         if (!$sth->execute($values)) {
             throw new DBException($sth);
         }
     } catch (PDOException $e) {
         throw new DBException($e);
     }
     return $sth;
 }