Think/Db/Driver.php
public function execute($str, $fetchSql = false)
    {
        $this->initConnect();
        if (!$this->_linkID) {
            return false;
        }
        $this->queryStr = $str;
        if (!empty($this->bind)) {
            $that = $this;
            $this->queryStr = strtr(
                $this->queryStr,
                array_map(
                    function ($val) use ($that) {
                        return '\''.$that->escapeString($val).'\'';
                    },
                    $this->bind
                )
            );
        }
        if ($fetchSql) {
            return $this->queryStr;
        }
        //释放前次的查询结果
        if (!empty($this->PDOStatement)) {
            $this->free();
        }
        $this->executeTimes++;
        // 记录写入操作
//            N('db_write', 1);
        // 记录开始执行时间
        $this->debug(true);
        $this->PDOStatement = $this->_linkID->prepare($str);
        if (false === $this->PDOStatement) {
            $this->error();

            return false;
        }
        foreach ($this->bind as $key => $val) {
            if (is_array($val)) {
                $this->PDOStatement->bindValue($key, $val[0], $val[1]);
            } else {
                $this->PDOStatement->bindValue($key, $val);
            }
        }
        $this->bind = [];
        try {
            $result = $this->PDOStatement->execute();
            // 调试结束
            $this->debug(false);
            if (false === $result) {
                $this->error();

                return false;
            } else {
                $this->numRows = $this->PDOStatement->rowCount();
                if (preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) {
                    $this->lastInsID = $this->_linkID->lastInsertId();
                }

                return $this->numRows;
            }
        } catch (PDOException $e) {
            $this->error();

            return false;
        }
    }
public function execute($str, $fetchSql = false)
    {
        $this->initConnect();
        if (!$this->_linkID) {
            return false;
        }
        $this->queryStr = $str;
        if (!empty($this->bind)) {
            $that = $this;
            $this->queryStr = strtr(
                $this->queryStr,
                array_map(
                    function ($val) use ($that) {
                        return '\''.$that->escapeString($val).'\'';
                    },
                    $this->bind
                )
            );
        }
        if ($fetchSql) {
            return $this->queryStr;
        }
        //释放前次的查询结果
        if (!empty($this->PDOStatement)) {
            $this->free();
        }
        $this->executeTimes++;
        // 记录写入操作
//            N('db_write', 1);
        // 记录开始执行时间
        $this->debug(true);
        $this->PDOStatement = $this->_linkID->prepare($str);
        if (false === $this->PDOStatement) {
            $this->error();

            return false;
        }
        foreach ($this->bind as $key => $val) {
            if (is_array($val)) {
                $this->PDOStatement->bindValue($key, $val[0], $val[1]);
            } else {
                $this->PDOStatement->bindValue($key, $val);
            }
        }
        $this->bind = [];
        try {
            $result = $this->PDOStatement->execute();
            // 调试结束
            $this->debug(false);
            if (false === $result) {
                $this->error();

                return false;
            } else {
                $this->numRows = $this->PDOStatement->rowCount();
                if (preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) {
                    $this->lastInsID = $this->_linkID->lastInsertId();
                }

                return $this->numRows;
            }
        } catch (PDOException $e) {
            $this->error();

            return false;
        }
    }
执行语句


@param string $str sql指令
@param bool $fetchSql 不执行只是获取SQL

@throws \PDOException
@return mixed