/** * Runs a query. Internal function, available for subclasses. 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 $affected_rows. If the debug flag is set * this function will send debugging output to screen buffer. * * @throws RedBean_Exception_SQL * * @param string $sql the SQL string to be send to database server * @param array $aValues the values that need to get bound to the query slots */ protected function runQuery($sql, $aValues) { $this->connect(); if ($this->debug && $this->logger) { $this->logger->log($sql, $aValues); } try { $this->doBinding($sql, $aValues); $this->affected_rows = oci_num_rows($this->statement); if (oci_num_fields($this->statement)) { $rows = array(); oci_fetch_all($this->statement, $rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW); // This rewrite all the php properties in lowercase foreach ($rows as $key => $row) { foreach ($row as $field => $value) { unset($rows[$key][$field]); $new_key = strtolower($field); $rows[$key][$new_key] = $value; } } $this->rs = $rows; if ($this->debug && $this->logger) { $this->logger->log('resultset: ' . count($this->rs) . ' rows'); } } else { $this->rs = array(); } } catch (PDOException $pdoException) { // Unfortunately the code field is supposed to be int by default (php) // So we need a property to convey the SQL State code. $transformedException = new RedBean_Exception_SQL($pdoException->getMessage(), 0); $transformedException->setSQLState($pdoException->getCode()); throw $transformedException; } }
/** * 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 * * @throws RedBean_Exception_SQL */ protected function runQuery($sql, $bindings, $options = array()) { $this->connect(); if ($this->debug && $this->logger) { $this->logger->log($sql, $bindings); } try { if (strpos('pgsql', $this->dsn) === 0) { $statement = $this->pdo->prepare($sql, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => TRUE)); } else { $statement = $this->pdo->prepare($sql); } $this->bindParams($statement, $bindings); $statement->execute(); $this->affectedRows = $statement->rowCount(); if ($statement->columnCount()) { $fetchStyle = isset($options['fetchStyle']) ? $options['fetchStyle'] : NULL; $this->resultArray = $statement->fetchAll($fetchStyle); if ($this->debug && $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->debug && $this->logger) { $this->logger->log('An error occurred: ' . $err); } $exception = new RedBean_Exception_SQL($err, 0); $exception->setSQLState($e->getCode()); throw $exception; } }
/** * 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 $affected_rows. If the debug flag is set * this function will send debugging output to screen buffer. * * @throws RedBean_Exception_SQL * * @param string $sql the SQL string to be send to database server * @param array $aValues the values that need to get bound to the query slots */ protected function runQuery($sql, $aValues) { $this->connect(); if ($this->debug && $this->logger) { $this->logger->log($sql, $aValues); } try { if (strpos('pgsql', $this->dsn) === 0) { $s = $this->pdo->prepare($sql, array(PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => true)); } else { $s = $this->pdo->prepare($sql); } $this->bindParams($s, $aValues); $s->execute(); $this->affected_rows = $s->rowCount(); if ($s->columnCount()) { $this->rs = $s->fetchAll(); if ($this->debug && $this->logger) { $this->logger->log('resultset: ' . count($this->rs) . ' rows'); } } else { $this->rs = 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->debug && $this->logger) { $this->logger->log('An error occurred: ' . $err); } $x = new RedBean_Exception_SQL($err, 0); $x->setSQLState($e->getCode()); throw $x; } }