执行SQL语句

@access public

@param null $sql
@param array $parameters
@return \PDOStatement 返回查询结果,
331917
public function execute($sql = null, $parameters = array()) {
		if (empty($sql)) {
			return null;
		}
		try {
			if (!empty($sql)) {
				$this->prepare($sql);
				$this->bind($parameters);
			}
			$this->result->execute();
		} catch (\PDOException  $ex) {
            if (Config::isDebug()) {
                Factory::log()->info(sprintf('PDO: %s => %s', $sql, $this->error), $parameters);
                throw $ex;
            }
			$this->error = $ex->getMessage();
		}
        return $this->result;
	}
670205
private function _queryPDO($sql, array $params = array())
    {
        try {
            $this->_queryId = self::$_linkId->prepare($sql);
            $i = 1;
            foreach ($params as $key => $val) {
                $type = $this->getPDOConstantType($val);
                $this->_queryId->bindValue($i, $val, $type);
                ++$i;
            }
            return $this->_queryId->execute();
        } catch (PDOException $e) {
            $this->_error = $e->getMessage();
            return false;
        }
    }
1273079
public function execute($sql, $params = null)
    {
        $stmt = $this->_pdo->prepare($sql);

        if (is_array($params)) {
            foreach ($params as $token => $value) {
                $stmt->bindValue($token, $value);
            }
        }

        try {
            $stmt->execute();
        } catch (PDOException $exception) {
            $this->_database->error('execute', $exception);
        }

        return $stmt;
    }
1329791
public function insert($sql, $parameters = array()) {
        DB::addQueryLog($sql, $parameters);
        return $this->getEngine()->insert($sql, $parameters);
    }
269667
public function prepareExecute(string $sql, array $params): ?PDOStatement
	{
		$this->statement = $this->prepareQuery($sql, $params);
		$this->statement->execute();

		return $this->statement;
	}
1217191
public function run_query($sql, array $params=null, array $driverOptions=array()) {
		try {
			$this->sth = null;
			$this->sth = $this->dbh->prepare($sql, $driverOptions);
			if($this->sth === false) {
				throw new \Exception(__METHOD__ .": STH is false... ". ToolBox::debug_print($this->dbh->errorInfo(),0));
			}
			// TODO: throw an exception on error (and possibly if there were no rows returned)
			$this->sth->execute($params); 
			$this->numRows = $this->sth->rowCount();
		}
		catch(PDOException $px) {
			throw new \Exception(__METHOD__ .": ". $px->getMessage());
		}
		return($this->numRows);
	}
682169
public function where($sql=null, $params=array())
    {
        $this->_where = new Criteria($sql, $params);

        return $this;
    }
365705
public function execute($sql, array $parameters = array())
    {
        $this->logger->info($sql, array('parameters' => $parameters));

        try {
            $statement = $this->getPdo()->prepare($sql);
            $statement->execute($parameters);
        } catch (PDOException $exception) {
            $this->logger->error($exception->getMessage());

            throw $exception;
        }

        return $statement;
    }
537515
function execQueryString($sql, $params = null)
    {
        if (!is_array($params) && !is_null($params)) {
            $params = array($params);
        }

        $stmt = $this->prepare($sql);
        $stmt->execute($params);
        return $stmt;
    }
1112690
public function query($sql = null)
    {
        if (!$sql) {
            $sqlWhere = '';
            if (!empty($this->getWhere())) {
                $sqlWhere = $this->getWhere();
            }

            $sqlLimit = '';
            if (!empty($this->getLimit())) {
                $sqlLimit = $this->getLimit();
            }

            $sqlOrder = '';
            $orderBy = $this->getOrderBy();
            if (!empty($orderBy)) {
                $sqlOrder = $orderBy;
            }

            $sqlSelect = "SELECT " . $this->getSelect();
            $sqlFrom = " FROM " . $this->getTable();

            $sql = $sqlSelect . $sqlFrom . $sqlWhere . $sqlOrder . $sqlLimit;
        }
        $this->setLastQuery($sql);

        try {
            $stmt = $this->db->prepare($sql);
            $this->setLastQuery($stmt->queryString, $this->getParameters());
            $stmt->execute($this->getParameters());
        } catch (\PDOException $e) {
            throw new DatabaseException($e->getMessage() . '<br>' . $this->getLastQuery()[0]);
        }

        $this->setResult($stmt);
        $this->clearQuery();

        return $this;
    }
268341
private function prepare(string $sql, array $params = []): \PDOStatement
    {
        return $this->pdo()->connectionProcess(function (Pdo $pdo) use ($sql, $params) {
            $stmt = $pdo->prepare($sql);

            if ($params) {
                $k = 1;

                foreach ($params as $key => $value) {
                    $stmt->bindValue(is_int($key) ? $k++ : $key, $value);
                }
            }

            $this->fire($sql, $params);

            $stmt->execute();

            $pdo->checkError();

            return $stmt;
        });
    }
180057
public function queryFastHandle(string $sql, $bind = []): \PDOStatement
    {
        if (!$bind) {
            return $this->connectWrite()->query($sql, \PDO::FETCH_ASSOC);
        }

        $stmt = $this->connectWrite()->prepare($sql);
        $ret = $stmt->execute($bind);

        //通常是参数绑定问题
        if (!$ret) {
            trigger_error('PDO语句参数绑定错误:' . $stmt->errorCode(), E_USER_ERROR);
        }
        return $stmt;
    }
578424
public function query($sql, array $parameters = [])
    {
        $parameters = $this->prepareArguments($sql, $parameters);
        $this->sendNotification(
            'query:pre',
            [
                'sql'           => $sql,
                'parameters'    => $parameters,
                'session_stamp' => $this->getSession()->getStamp(),
            ]
        );
        $start    = microtime(true);
        $resource = $this->doQuery($sql, $parameters);
        $end      = microtime(true);

        $iterator = new ConvertedResultIterator(
            $resource,
            $this->getSession()
        );
        $this->sendNotification(
            'query:post',
            [
                'result_count' => $iterator->count(),
                'time_ms'      => sprintf("%03.1f", ($end - $start) * 1000),
            ]
        );

        return $iterator;
    }
686312
public function prepare(string $sql, array $params = []): Statement
    {
        if (!$stmt = $this->connection->prepare($sql)) {
            $error = [
                'error' => $this->connection->error,
                'errno' => $this->connection->errno,
                'sqlstate' => $this->connection->sqlstate
            ];

            throw new SqlException('Failed to prepare statement', [$error], $sql, $params);
        }

        if (!empty($params)) {
            if (!$stmt->bind_param(self::getMysqlParamTypes($params), ...$params)) {
                throw new SqlException('Failed to bind params', $stmt->error_list, $sql, $params);
            }
        }

        return new Statement($stmt, $this->usedPrepare, $sql, $params);
    }
678145
public function execute(&$SQL, $parameters = array(), &$count = false)
    {
        if (is_array($SQL)) {
            $SQL = implode(' ', $SQL);
        }
        echo $SQL.PHP_EOL;
        if (is_string($SQL)) {
            $SQL = new Request($this->PDO, $SQL);
        }
        $result = $SQL->execute($parameters);
        return $result;
    }
366941
public function run_update($sql, array $params=null, array $driverOptions=array()) {
		return($this->run_query($sql, $params, $driverOptions));
	}
733086
public function startQuery($sql, array $params = null, array $types = null) {
    	
    	$str  = "\n==========================\n";
    	$str .= "Sql: " . $sql . "\n";
    	$str .= "Params: " . print_r($params, true) . "\n"; 
    	$str .= "Types: " . print_r($types, true) . "\n";
    	$str .= "==========================\n";
    	$this->logger->debug($str);
    	
    }