/** * Execute a raw SQL query on the database. * * @param string $sql Raw SQL string to execute. * @param array &$values Optional array of bind values * @return mixed A result set object */ public function query($sql, $values=array()) { $this->last_query = $sql; Logger::debug($sql . ' => ' . var_export($values,true)); try { if (!($sth = $this->connection->prepare($sql))) Logger::error('PDO Prepare ERROR!' . ' SQL:' . $sql); } catch (PDOException $e) { Logger::error(array($e->getMessage(), $e->getTraceAsString())); } $sth->setFetchMode(PDO::FETCH_ASSOC); try { if (!$sth->execute($values)){ Logger::error(array('PDO Exec ERROR!', "SQL: " . $sql , "VALUES: " . var_export($values, true) ,'PDO: ' . $sth->errorInfo())); throw new Database_Exception("PDO Exec ERROR! (1)", $e->getCode() , $e); } } catch (PDOException $e) { Logger::error(array('PDO Exec ERROR!' , "SQL: " . $sql , "VALUES: " . var_export($values, true) , "PDO: " . $e->getMessage())); throw $e; } return $sth; }