ManaPHP\Db::query PHP Method

query() public method

Use this method only when the SQL statement sent to the server is returning rows Querying data $resultset = $connection->query("SELECT * FROM robots WHERE type='mechanical'"); $resultset = $connection->query("SELECT * FROM robots WHERE type=?", array("mechanical"));
public query ( string $sql, array $bind = [], integer $fetchMode = PDO::FETCH_ASSOC ) : PdoStatement
$sql string
$bind array
$fetchMode integer
return PdoStatement
    public function query($sql, $bind = [], $fetchMode = \PDO::FETCH_ASSOC)
    {
        $this->_sql = preg_replace('#\\[([a-z_][a-z0-9_]*)\\]#i', '`\\1`', $sql);
        $this->_bind = $bind;
        $this->_affectedRows = 0;
        $this->fireEvent('db:beforeQuery');
        try {
            if (count($bind) !== 0) {
                $statement = $this->_pdo->prepare($this->_sql);
                $statement = $this->_executePrepared($statement, $bind);
            } else {
                $statement = $this->_pdo->query($this->_sql);
            }
            $this->_affectedRows = $statement->rowCount();
            $statement->setFetchMode($fetchMode);
        } catch (\PDOException $e) {
            throw new DbException(':message . ' . PHP_EOL . 'SQL: ":sql"' . PHP_EOL . ' BIND: :bind', ['message' => $e->getMessage(), 'sql' => $this->_sql, 'bind' => json_encode($this->_bind, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)]);
        }
        $this->fireEvent('db:afterQuery');
        return $statement;
    }