Runs the SQL query in read-only mode from the database

@param string $sql The SQL query to run

@return PDOStatement The query result
@see http://us.php.net/manual/en/pdo.query.php
437691
public function read($sql)
    {
        $sql = (string)$sql;

        $conn = $this->getConnection();
        $this->Benchmark->start('sql-query');

        try {

//            if(!substr($sql, 0, 4) == 'SHOW') {
//
//                $explain = $conn->query("EXPLAIN ".$sql);
//
//                $explainresults = $explain->fetchAll(PDO::FETCH_ASSOC);
//            }

//            $start =  microtime(TRUE);

            $result = $conn->query($sql);

//            $end =  microtime(TRUE);
//            $totalms = ($end-$start)*1000;

//            if($totalms > 1 && !empty($explainresults)) {
//
//                foreach($explainresults as $qline)
//                {
//
//                    if(strtolower($qline['select_type']) != 'union result' && strtolower($qline['type']) == 'all')
//                    {
//                        // table scan
//                        $pr = ArrayUtils::arrayToStr($explainresults);
//                        error_log("[SQL]  BAD QUERY: TABLE SCAN {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n");
//
//                    }else if($qline['rows'] > 5000) {
//
//                        // poor index
//                        $pr = ArrayUtils::arrayToStr($explainresults);
//                        error_log("[SQL]  BAD QUERY: SCANNED OVER 5000 ROWS {$qline['key']}\n"."SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n");
//
//                    }
//                }
//
//            }
//
//            if($totalms > 1000) {
//
//                if(!empty($explainresults)) {
//                    $pr = ArrayUtils::arrayToStr($explainresults);
//                    $email = "SQL:\n\n{$sql}\n\nEXPLAIN:\n\n{$pr}\n\nTOTAL TIME:{$totalms}ms\n";
//                } else {
//                    $email = "SQL:\n\n{$sql}\n\nTOTAL TIME:{$totalms}ms\n";
//                }
//                error_log("[SQL]  BAD QUERY: TOOK OVER 1 SECOND\n".$email);
//
//            }




        } catch(PDOException $pe) {
            $errorMessage = $pe->getMessage();

            $this->Logger->debug(array(
                'Conn'                => $this->connDebugString,
                'SQL'                 => $sql,
                'Execution Time (ms)' => $this->Benchmark->end('sql-query'),
                'Error'               => $errorMessage,
            ));


            throw new SQLException($sql, $errorMessage, intVal($pe->getCode()));
        }

        $this->Logger->debug(array(
                'Conn'                => $this->connDebugString,
                'SQL'                 => $sql,
                'Execution Time (ms)' => $this->Benchmark->end('sql-query'),
                'Rows Returned'       => $result->rowCount(),
            ));

        unset($sql);
        unset($conn);

        return $result;
    }
1197634
protected function _execute($sql)
	{
		return $this->is_write_type($sql)
			? $this->conn_id->exec($sql)
			: $this->conn_id->query($sql);
	}
818188
public function prepare($sql)
    {
        return $this->getDisconnectRetry()->run(function () use ($sql) {
            $statement = $this->_driver->prepare($sql);

            if ($this->_logQueries) {
                $statement = $this->_newLogger($statement);
            }

            return $statement;
        });
    }
342091
public function query($sql)
    {
        if (!$queryResource = mysql_query($sql, $this->dbConn)) {
            echo mysql_error();
            $this->handleError();
        } else {
            return new MySqlResult($this, $queryResource);
        }
    }
56041
protected function prepareSql($sql)
    {
        $sql = str_replace(";',", "-CODE-", $sql);
        $sql = trim($sql);
        preg_match_all('#DELIMITER (.+?)\n(.+?)DELIMITER ;#s', $sql, $m);
        foreach ($m[0] as $k => $v) {
            if ($m[1][$k] == '|') {
                throw new \RuntimeException('You can not use "|" as delimiter: '.$v);
            }
            $stored = str_replace(';', '|', $m[2][$k]);
            $stored = str_replace($m[1][$k], ";\n", $stored);
            $sql = str_replace($v, $stored, $sql);
        }
        $query = array();

        $tab = explode(";\n", $sql);
        $size = \count($tab);
        for ($i = 0; $i < $size; $i++) {
            $queryTemp = str_replace("-CODE-", ";',", $tab[$i]);
            $queryTemp = str_replace("|", ";", $queryTemp);
            $query[] = $queryTemp;
        }

        return $query;
    }
715641
public function prepare(string $sql = null)
    {
        $this->sqlQuery = $this->getConnection()->prepare($this->getSql($sql));

        return $this;
    }
58029
public function query($sql)
    {
        if (true == Config::get('sql_log')) {
            wlog('SQL-Log', $sql);
        }

        if (true == ($rs = mysql_query($sql, $this->db))) {
            $GLOBALS['__$DB_QUERY_COUNT']++;
            return $rs;
        } else {
            throw_error('DB_ERROR: ' . mysql_error($this->db) . "\nRAW_SQL: " . $sql, 2045);
        }
    }
1264072
protected function query_row ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		try 
		{
			$all = $this->conn->query($sql, PDO::FETCH_NUM);
			$row = array();
			foreach ($all as $r) {
				$row = $r;
				break;
			}
		}
		catch (PDOException $e)
		{
			$this->sql_errcheck($sql);
		}
		return $row;
	}
1344234
public function exec(string $sql)
    {
        try {
            return $this->dbh->exec($sql);
        } catch (\PDOException $e) {
            die("Error: " . $e->getMessage());
        }
    }
236272
public function exec($sql)
    {
        $this->writeToLog("Exec: " . $sql);
        $result = parent::exec($sql);
        return $result;
    }
1171730
public function run($sql, array $params = array())
    {
        $sth = $this->pdo->prepare($sql);

        foreach ($params as $key => $value) {
            $key = is_numeric($key) ? $key + 1 : ":$key";
            $sth->bindValue($key, $value);
        }

        $sth->execute($params);
        $this->executed[] = $sql;
        return $sth;
    }
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;
	}
687229
public function query($sql) {
        try {
            $lastExecMode = $this->skipResults;
            $this->skipResults = false;

            /** @var \SQLite3Result $result */
            $result = $this->executeRaw($sql);
            return new SQLiteResult($this, $sql, $result, $this->lastInsertId(), $this->lastAffectedRows());
        }
        finally {
            $this->skipResults = $lastExecMode;
        }
    }
6382
public function execute($sql)
    {
        try{
            if(null === $this->queryType)
            {
                $this->queryType = QueryType::WRITE;
            }
            if(!$this->isInitDb)
            {
                $this->db = Db::getInstance($this->poolName, $this->queryType);
            }
            if(!$this->db)
            {
                return new Result(false);
            }
            $stmt = $this->db->prepare($sql);
            if($stmt)
            {
                if($this->defer)
                {
                    $defer = $stmt->deferExecute($this->binds);
                }
                else
                {
                    $stmt->execute($this->binds) ? $stmt : false;
                }
            }
            return new Result($stmt, $this->modelClass, $defer ?? null);
        } finally {
            $this->__init();
        }
    }
641110
public function exec($sql)
    {
        if ($sql instanceof Zend_Db_Select) {
            $sql = $sql->assemble();
        }

        try {
            $affected = $this->getConnection()->exec($sql);

            if ($affected === false) {
                $errorInfo = $this->getConnection()->errorInfo();
                /**
                 * @see Zend_Db_Adapter_Exception
                 */
                // require_once 'Zend/Db/Adapter/Exception.php';
                throw new Zend_Db_Adapter_Exception($errorInfo[2]);
            }

            return $affected;
        } catch (PDOException $e) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            // require_once 'Zend/Db/Adapter/Exception.php';
            throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }
220107
public function execute($sql)
    {
        if ($this->hasProfiler()) {
            if ($profile = $this->getProfiler()->start()) {
                $profile->setName($sql);
                $profile->setAdapter($this);
            }
        }

        $result = $this->query($sql);

        if ($this->hasProfiler() && $profile !== null) {
            $this->getProfiler()->end($profile);
        }

        if ($result !== false) {
            return $result;
        } else {
            trigger_error($this->error() . " [$sql]", E_USER_WARNING);
        }

        return false;
    }
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);
        }
    }