queryInternal() protected method

Performs the actual DB query of a SQL statement.
Since: 2.0.1 this method is protected (was private before).
protected queryInternal ( string $method, integer $fetchMode = null ) : mixed
$method string method of PDOStatement to be called
$fetchMode integer the result fetch mode. Please refer to [PHP manual](http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php) for valid fetch modes. If this parameter is null, the value set in [[fetchMode]] will be used.
return mixed the method execution result
コード例 #1
0
ファイル: DbCommand.php プロジェクト: yii2-tools/yii2-base
 /**
  * Actual query with caching results in local for current request
  * @inheritdoc
  */
 protected function queryInternal($method, $fetchMode = null)
 {
     if ($method !== '') {
         $rawSql = $this->getRawSql();
         $requestLocalCacheKey = implode('', [__CLASS__, $method, $fetchMode, $this->db->dsn, $this->db->username, preg_replace('/\\s+/', '', $rawSql)]);
         mb_convert_encoding($requestLocalCacheKey, 'UTF-8', 'UTF-8');
         if (($result = static::$requestLocalCache->get($requestLocalCacheKey)) !== false) {
             Yii::info('Query result served from request local cache' . PHP_EOL . 'Query: ' . VarDumper::dumpAsString($rawSql) . PHP_EOL . 'Result: ' . VarDumper::dumpAsString($result), __METHOD__);
             return $result;
         }
         static::$requestLocalCache->set('rawSql', $rawSql);
     }
     $result = parent::queryInternal($method, $fetchMode);
     if ($method !== '') {
         static::$requestLocalCache->set($requestLocalCacheKey, $result);
     }
     return $result;
 }
コード例 #2
0
 /**
  * Performs the actual DB query of a SQL statement.
  * @param string $method method of PDOStatement to be called
  * @param integer $fetchMode the result fetch mode. Please refer to [PHP manual](http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php)
  * for valid fetch modes. If this parameter is null, the value set in [[fetchMode]] will be used.
  * @return mixed the method execution result
  * @throws Exception2 if the query causes any problem
  * @since 2.0.1 this method is protected (was private before).
  */
 protected function queryInternal($method, $fetchMode = null)
 {
     if ($method !== '') {
         return parent::queryInternal($method, $fetchMode);
     }
     $rawSql = $this->getRawSql();
     Yii::info($rawSql, 'yii\\db\\Command::query');
     $this->prepare(true);
     $token = $rawSql;
     try {
         Yii::beginProfile($token, 'yii\\db\\Command::query');
         $this->pdoStatement->execute();
         $result = new DataReader($this);
         Yii::endProfile($token, 'yii\\db\\Command::query');
     } catch (Exception $e) {
         Yii::endProfile($token, 'yii\\db\\Command::query');
         throw $this->db->getSchema()->convertException($e, $rawSql);
     }
     return $result;
 }