src/Db/MySqlDb.php
public function query($sql, $type = Db::QUERY_READ, $options = []) {
        $mode = val(Db::OPTION_MODE, $options, $this->mode);

        if ($mode & Db::MODE_ECHO) {
            echo trim($sql, "\n;").";\n\n";
        }
        if ($mode & Db::MODE_SQL) {
            return $sql;
        }

        $result = null;
        if ($mode & Db::MODE_EXEC) {
            $result = $this->pdo()->query($sql);

            if ($type == Db::QUERY_READ) {
                $result->setFetchMode(PDO::FETCH_ASSOC);
                $result = $result->fetchAll();
                $this->rowCount = count($result);
            } elseif (is_object($result) && method_exists($result, 'rowCount')) {
                $this->rowCount = $result->rowCount();
                $result = $this->rowCount;
            }
        } elseif ($mode & Db::MODE_PDO) {
            /* @var \PDOStatement $result */
            $result = $this->pdo()->prepare($sql);
        }

        return $result;
    }
public function query($sql, $type = Db::QUERY_READ, $options = []) {
        $mode = val(Db::OPTION_MODE, $options, $this->mode);

        if ($mode & Db::MODE_ECHO) {
            echo trim($sql, "\n;").";\n\n";
        }
        if ($mode & Db::MODE_SQL) {
            return $sql;
        }

        $result = null;
        if ($mode & Db::MODE_EXEC) {
            $result = $this->pdo()->query($sql);

            if ($type == Db::QUERY_READ) {
                $result->setFetchMode(PDO::FETCH_ASSOC);
                $result = $result->fetchAll();
                $this->rowCount = count($result);
            } elseif (is_object($result) && method_exists($result, 'rowCount')) {
                $this->rowCount = $result->rowCount();
                $result = $this->rowCount;
            }
        } elseif ($mode & Db::MODE_PDO) {
            /* @var \PDOStatement $result */
            $result = $this->pdo()->prepare($sql);
        }

        return $result;
    }
Execute a query on the database.

@param string $sql The sql query to execute.
@param string $type One of the Db::QUERY_* constants.

Db::QUERY_READ
: The query reads from the database.

Db::QUERY_WRITE
: The query writes to the database.

Db::QUERY_DEFINE
: The query alters the structure of the datbase.

@param array $options Additional options for the query.

Db::OPTION_MODE
: Override {@link Db::$mode}.

@return array|string|PDOStatement|int Returns the result of the query.

array
: Returns an array when reading from the database and the mode is {@link Db::MODE_EXEC}.
string
: Returns the sql query when the mode is {@link Db::MODE_SQL}.
PDOStatement
: Returns a {@link \PDOStatement} when the mode is {@link Db::MODE_PDO}.
int
: Returns the number of rows affected when performing an update or an insert.