public static function query(string $sql, array $params = [], string $instance = Pool::INSTANCE, string $className = '', array $resultDecorators = []): ResultInterface
    {
        $type     = self::getOperation($sql);
        $instance = explode('.', $instance);
        list($instance, $node, $db) = array_pad($instance, 3, '');

        list($instance, $node) = self::getInstanceAndNodeByType($instance, $node, $type);
        /* @var AbstractDbConnection $connection */
        $connection = self::getConnection($instance, $node);

        if (!empty($db)) {
            $connection->selectDb($db);
        }

        /* @var DbPool $pool */
        $pool = $connection->getPool();
        /* @var DbPoolProperties $poolConfig */
        $poolConfig = $pool->getPoolConfig();
        $driver = $poolConfig->getDriver();

        if (App::isCoContext()) {
            $connection->setDefer();
        }

        $sqlId = uniqid();
        $profileKey = sprintf('%s.%s', $driver, $sqlId);
        Log::debug(sprintf('Execute sqlId=%s , sql=%s', $sqlId, $sql));

        Log::profileStart($profileKey);
        $connection->prepare($sql);
        $params = self::transferParams($params);
        $result = $connection->execute($params);

        $dbResult = self::getResult($result, $connection, $profileKey);
        $dbResult->setType($type);
        $dbResult->setClassName($className);
        $dbResult->setDecorators($resultDecorators);

        return $dbResult;
    }
public static function query(string $sql, array $params = [], string $instance = Pool::INSTANCE, string $className = '', array $resultDecorators = []): ResultInterface
    {
        $type     = self::getOperation($sql);
        $instance = explode('.', $instance);
        list($instance, $node, $db) = array_pad($instance, 3, '');

        list($instance, $node) = self::getInstanceAndNodeByType($instance, $node, $type);
        /* @var AbstractDbConnection $connection */
        $connection = self::getConnection($instance, $node);

        if (!empty($db)) {
            $connection->selectDb($db);
        }

        /* @var DbPool $pool */
        $pool = $connection->getPool();
        /* @var DbPoolProperties $poolConfig */
        $poolConfig = $pool->getPoolConfig();
        $driver = $poolConfig->getDriver();

        if (App::isCoContext()) {
            $connection->setDefer();
        }

        $sqlId = uniqid();
        $profileKey = sprintf('%s.%s', $driver, $sqlId);
        Log::debug(sprintf('Execute sqlId=%s , sql=%s', $sqlId, $sql));

        Log::profileStart($profileKey);
        $connection->prepare($sql);
        $params = self::transferParams($params);
        $result = $connection->execute($params);

        $dbResult = self::getResult($result, $connection, $profileKey);
        $dbResult->setType($type);
        $dbResult->setClassName($className);
        $dbResult->setDecorators($resultDecorators);

        return $dbResult;
    }
public static function query ( string $ sql , array $ params = [ ] , string $ instance = Pool :: INSTANCE , string $ className = '' , array $ resultDecorators = [ ] ) : ResultInterface { $ type = self :: getOperation ( $ sql ) ; $ instance = explode ( '.' , $ instance ) ; list ( $ instance , $ node , $ db ) = array_pad ( $ instance , 3 , '' ) ; list ( $ instance , $ node ) = self :: getInstanceAndNodeByType ( $ instance , $ node , $ type ) ; /* @var AbstractDbConnection $connection */ $ connection = self :: getConnection ( $ instance , $ node ) ; if ( ! empty ( $ db ) ) { $ connection -> selectDb ( $ db ) ; } /* @var DbPool $pool */ $ pool = $ connection -> getPool ( ) ; /* @var DbPoolProperties $poolConfig */ $ poolConfig = $ pool -> getPoolConfig ( ) ; $ driver = $ poolConfig -> getDriver ( ) ; if ( App :: isCoContext ( ) ) { $ connection -> setDefer ( ) ; } $ sqlId = uniqid ( ) ; $ profileKey = sprintf ( '%s.%s' , $ driver , $ sqlId ) ; Log :: debug ( sprintf ( 'Execute sqlId=%s , sql=%s' , $ sqlId , $ sql ) ) ; Log :: profileStart ( $ profileKey ) ; $ connection -> prepare ( $ sql ) ; $ params = self :: transferParams ( $ params ) ; $ result = $ connection -> execute ( $ params ) ; $ dbResult = self :: getResult ( $ result , $ connection , $ profileKey ) ; $ dbResult -> setType ( $ type ) ; $ dbResult -> setClassName ( $ className ) ; $ dbResult -> setDecorators ( $ resultDecorators ) ; return $ dbResult ; }
Query by sql

@param string $sql
@param array $params
@param string $instance
@param string $className
@param array $resultDecorators
@return \Swoft\Core\ResultInterface|DbResult
@throws DbException
Query by sql