src/Leevel/Database/Connect.php
public function query(string $sql, array $bindParams = [], $master = false, ?int $fetchStyle = null, $fetchArgument = null, array $ctorArgs = [])
    {
        $this->initSelect();

        $this->setLastSql($sql, $bindParams);

        if (!in_array(($sqlType = $this->normalizeSqlType($sql)), [
            'select',
            'procedure',
        ], true)) {
            throw new InvalidArgumentException(
                'The query method only allows select and procedure SQL statements.'
            );
        }

        $this->pdoStatement = $this->pdo($master)->prepare($sql);

        $this->bindParams($bindParams);

        try {
            $this->pdoStatement->execute();
            $this->reconnectRetry = 0;
        } catch (PDOException $e) {
            if ($this->needReconnect($e)) {
                $this->reconnectRetry++;
                $this->close();

                return self::query($sql, $bindParams, $master, $fetchStyle, $fetchArgument, $ctorArgs);
            }

            throw $e;
        }

        $this->numRows = $this->pdoStatement->rowCount();

        return $this->fetchResult($fetchStyle, $fetchArgument, $ctorArgs, 'procedure' === $sqlType);
    }
public function query(string $sql, array $bindParams = [], $master = false, ?int $fetchStyle = null, $fetchArgument = null, array $ctorArgs = [])
    {
        $this->initSelect();

        $this->setLastSql($sql, $bindParams);

        if (!in_array(($sqlType = $this->normalizeSqlType($sql)), [
            'select',
            'procedure',
        ], true)) {
            throw new InvalidArgumentException(
                'The query method only allows select and procedure SQL statements.'
            );
        }

        $this->pdoStatement = $this->pdo($master)->prepare($sql);

        $this->bindParams($bindParams);

        try {
            $this->pdoStatement->execute();
            $this->reconnectRetry = 0;
        } catch (PDOException $e) {
            if ($this->needReconnect($e)) {
                $this->reconnectRetry++;
                $this->close();

                return self::query($sql, $bindParams, $master, $fetchStyle, $fetchArgument, $ctorArgs);
            }

            throw $e;
        }

        $this->numRows = $this->pdoStatement->rowCount();

        return $this->fetchResult($fetchStyle, $fetchArgument, $ctorArgs, 'procedure' === $sqlType);
    }
查询数据记录.

@param string   $sql           sql 语句
@param array    $bindParams    sql 参数绑定
@param bool|int $master
@param int      $fetchStyle
@param mixed    $fetchArgument
@param array    $ctorArgs

@return mixed