Internal helper method for executing statments. Logs queries, and
stores statement object in ::_last_statment, accessible publicly
through ::get_last_statement()
protected static _execute ( string $query, array $parameters = [], string $connection_name = self::DEFAULT_CONNECTION ) : boolean | ||
$query | string | |
$parameters | array | An array of parameters to be bound in to the query |
$connection_name | string | Which connection to use |
return | boolean | Response of PDOStatement::execute() |
/** * Execute the SELECT query that has been built up by chaining methods * on this class. Return an array of rows as associative arrays. */ protected function _run() { // allow parent method to run if (!$this->cnt_query) { // need a way to make sure this is set if ($this->_is_raw_query) { if (is_array($this->_raw_parameters)) { foreach ($this->_raw_parameters as $k => $v) { if (!is_numeric($v)) { $v = '"' . $v . '"'; } $this->_raw_query = str_replace(':' . $k, $v, $this->_raw_query); } } } return parent::_run(); } // we are not caching the COUNT - @todo - implement caching $query = $this->_build_select(); parent::_execute($query, $this->_values, $this->_connection_name); $statement = parent::get_last_statement(); $rows = array(); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { $rows[] = $row; } // reset Idiorm bound values $this->_values = array(); return $rows; }