写入SQL语句
@param  string $sql 要写入的SQL语句
@return boolean     true - 写入成功，false - 写入失败！
767450
private function write($sql)
    {
        $size = strlen($sql);
        //由于压缩原因，无法计算出压缩后的长度，这里假设压缩率为50%，
        //一般情况压缩率都会高于50%；
        $size = $this->config['compress'] ? $size / 2 : $size;
        $this->open($size);
        return $this->config['compress'] ? @gzwrite($this->fp, $sql) : @fwrite($this->fp, $sql);
    }
945431
public function execute(string $sql, $bind = [])
    {
        $sql = trim($sql);

        // 执行前置钩子
        $ret = $this->before('Execute', $sql, $bind);

        //如果被前置钩子阻止
        if ($ret === self::INTERRUPT) {
            return null;
        }

        //前置钩子修正参数
        list($sql, $bind) = $ret;

        //准备语句
        $this->statement->execute($sql, $bind);

        //要记录日志的数据
        $data = ['sql' => $sql, 'bind' => $bind];

        // 如果允许多表访问,直接通过
        if ($this->enableMulti()) {
            // 执行具体删除操作
            $result = self::log('execute', $data, '*', '', false, false);

            // 获取执行结果,执行后置钩子
            return $this->after('Execute', $result);
        }

        // 识别语句中的表名
        $tables = $this->statement->getTable();

        // 未能识别出表名,直接通过,这有可能是Desc/commit/rollback/begin
        if (!$tables or count($tables) == 0) {
            // 执行具体删除操作
            $result = self::log('execute', $data, '*', '', false, false);
            // 获取执行结果,执行后置钩子
            return $this->after('Execute', $result);
        }

        // 如果识别出多个表名
        if (count($tables) > 1) {
            trigger_error('执行语句中不允许同时指定多个表名', E_USER_ERROR);
        }

        // 取表名
        $table = $tables[0];

        // 如果语句中的表名与初始化时不同,则错误
        if ($table != $this->tableName) {
            trigger_error('表名不匹配:' . $this->tableName . ':' . $sql, E_USER_ERROR);
        }

        // 执行具体删除操作
        $result = self::log('execute', $data, '*', '', false, false);

        // 获取执行结果,执行后置钩子
        return $this->after('Execute', $result);
    }
58656
public function execute($sql) {

        //如果开启了调试模式，那么把所有对数据库写操作的语句记录下来
        if ( SQL_LOG &&
            (strpos($sql, 'INSERT') !== false
                || strpos($sql, 'DELETE') !== false
                || strpos($sql, 'REPLACE') !== false
                    || strpos($sql, 'UPDATE') !== false)) {
            Log::info($sql, 'sql');
        }
        if ( $this->link == null ) $this->connect();
        try {
            $result = $this->link->query($sql);
        } catch ( PDOException $e ) {
            $exception = new DBException("SQL错误:" . $e->getMessage());
            $exception->setCode($e->getCode());
            $exception->setQuery($sql);
            if ( APP_DEBUG ) {
                __print($sql);
            }
            throw $exception;
        }
        return $result;
    }
1313189
function multi_query($sql)
    {
        $result = $this->tryReconnect(array('parent', 'multi_query'), array($sql));
        if (!$result)
        {
            Swoole\Error::info(__CLASS__ . " SQL Error", $this->errorMessage($sql));
            return false;
        }

        $result = call_user_func_array(array('parent', 'use_result'), array());
        $output = array();
        while ($row = $result->fetch_assoc())
        {
            $output[] = $row;
        }
        $result->free();

        while (call_user_func_array(array('parent', 'more_results'), array()) && call_user_func_array(array(
                'parent',
                'next_result'
            ), array()))
        {
            $extraResult = call_user_func_array(array('parent', 'use_result'), array());
            if ($extraResult instanceof \mysqli_result)
            {
                $extraResult->free();
            }
        }

        return $output;
    }
1219284
protected function sql($sql = null, $replace = false)
    {
        if (null !== $sql) {
            if (!isset($this->oosql_sql[$this->oosql_table]) || $replace) {
                $this->oosql_sql[$this->oosql_table] = $sql;
            } else {

                $this->oosql_sql[$this->oosql_table] .= $sql;
            }
            return;
        }
        return $this->oosql_sql[$this->oosql_table];
    }
108411
public static function exec($sql)
    {
        exception_if(self::$server == 'out', AppSetupException::class);

        self::$server->exec($sql);

        return true;
    }
532880
public function query($sql)
    {
        #鉴定是执行查询还是commit提交操作。如果是select、show，可以有后续操作。
        $_key = strtolower(substr($sql, 0, 4));
        if ($_key == 'sele' || $_key == 'show') {
            $this->query_sql = $sql;
            return $this;
        } else {
            return $this->conn('master')->query($sql);
        }
    }
570395
public function exec($sql)
    {
        if ($this->useDebug) {
            $debug = $this->getDebugSnapshot();
        }

        $return = parent::exec($sql);

        if ($this->useDebug) {
            $this->log($sql, null, __METHOD__, $debug);
            $this->setLastExecutedQuery($sql);
            $this->incrementQueryCount();
        }

        return $return;
    }
1307572
protected function query($sql) {
        $vars = func_get_args();
		$cleaner = "/[\s,].+|[^a-zA-Z]/";
		$illegal = "/[\\\\'\"\%]/";
        try {
            $pdo = $this->dbConnect();
            $stmt = $pdo->prepare($sql);
            $binds = explode(':', $sql);
            foreach($binds as $n => $b) {
				if($n != 0 && substr($b,1)!=false) {
					$b = ':' . preg_replace($cleaner,'',$b);
					$vars[$n] = preg_replace($illegal,'',$vars[$n]);
					$stmt->bindParam($b,$vars[$n]);
				}
            }
            $stmt->execute();
            return (strpos($sql,'SELECT') !== FALSE) ? $stmt->fetchAll() : true;
        } catch(PDOException $e) {
            return array('query_error' => $e);
        }
    }
696035
protected function isQueryType($sql, $type)
    {
        if (!preg_match('/^(?<operation>\w+)\b/', $sql, $matches)) {
            return false;
        }
        $operation = $matches['operation'];
        if (is_array($type)) {
            return in_array(strtolower($operation), $type);
        } else {
            return strcasecmp($sql, $type) === 0;
        }
    }
236272
public function exec($sql)
    {
        $this->writeToLog("Exec: " . $sql);
        $result = parent::exec($sql);
        return $result;
    }
930668
public function query($sql)
    {
        try {
            $result = $this->getConnect()->query($sql);
        } catch (mysqli_sql_exception $exception) {
            $reflect = new ReflectionClass($exception);
            $property = $reflect->getProperty('sqlstate');
            $property->setAccessible(true);
            throw (new Exceptions\QueryException($exception->getMessage(), $property->getValue($exception)))
                ->setQuery($sql);
        }

        return $result;
    }
1358744
protected function query_row ( $sql )
    {
        $sql = $this->sql_printf(func_get_args());
        if (!($res = pg_query($this->conn, $sql)))
        {
            $this->sql_errcheck($sql);
        }
        if ($row = pg_fetch_array($res))
        {
            $rs = $row;
        }
        else
        {
            $rs = false;
        }
        pg_free_result($res);
        return $rs;
    }
170953
protected function query_one ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		if (!($res = mysql_query($sql, $this->conn)))
		{
			$this->sql_errcheck($sql);
		}
		$val = @mysql_result($res, 0, 0);
		mysql_free_result($res);
		return $val;
	}
1221076
protected function query_one ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		if (!($res = mysqli_query( $this->conn, $sql)))
		{
			$this->sql_errcheck($sql);
		}
		if ($row = mysqli_fetch_assoc($res))
		{
			$val = array_pop($row);
		}
		else
		{
			$val = false;
		}
		((mysqli_free_result($res) || (is_object($res) && (get_class($res) == "mysqli_result"))) ? true : false);
		return $val;
	}
1344234
public function exec(string $sql)
    {
        try {
            return $this->dbh->exec($sql);
        } catch (\PDOException $e) {
            die("Error: " . $e->getMessage());
        }
    }
877880
protected function query_one ( $sql )
	{
		list($sql, $args) = $this->sql_args(func_get_args());
		return any_db_query_one($sql, $args);
	}