/** * Executes the current select object and returns the result * * @param integer $fetchMode OPTIONAL * @param mixed $bind An array of data to bind to the placeholders. * @return \Micro\Database\Statement */ public function query($fetchMode = null, $bind = array()) { if (!empty($bind)) { $this->bind($bind); } $stmt = $this->_adapter->query($this); if ($fetchMode == null) { $fetchMode = $this->_adapter->getFetchMode(); } $stmt->setFetchMode($fetchMode); return $stmt; }
/** * Special handling for PDO query(). * All bind parameter names must begin with ':' * * @param string|\Micro\Database\Select $sql The SQL statement with placeholders. * @param array $bind An array of data to bind to the placeholders. * @return \Micro\Database\Statement\Pdo * @throws \Micro\Database\Statement\Exception To re-throw \PDOException. */ public function query($sql, $bind = array()) { if (empty($bind) && $sql instanceof Select) { $bind = $sql->getBind(); } if (is_array($bind)) { foreach ($bind as $name => $value) { if (!is_int($name) && !preg_match('/^:/', $name)) { $newName = ":{$name}"; unset($bind[$name]); $bind[$newName] = $value; } } } try { return parent::query($sql, $bind); } catch (\PDOException $e) { throw new StatementException($e->getMessage(), $e->getCode(), $e); } }
/** * Support method for fetching rows. * * @param Select $select query options. * @return array An array containing the row results in FETCH_ASSOC mode. */ protected function _fetch(Select $select) { $stmt = $this->_db->query($select); $data = $stmt->fetchAll(Database::FETCH_ASSOC); return $data; }