当我尝试在 yii 框架中执行查询时连接被重置

Connection was reset when I try to execute a query in the yii framework

当我尝试连接到我的数据库时,一切正常,但是当我尝试使用 query() 命令执行 SQL 语句时,我得到此错误:

The connection was reset

The connection to the server was reset while the page was

页面未加载。

$sql = <<<SQL
SELECT
1
FROM
dual
SQL;
$oci=Yii::app()->db;
$command = $oci->createCommand($sql);
$dataReader = $command->query();

我正在尝试在 index.php 页面中执行此操作,如果我评论最后一行,页面加载成功。

我测试了与 echo isset(Yii::app()->db); 的连接,我得到了 1。

我正在使用 oci8Pdo.OciDbConnection class。

编辑:

print_r($command) 结果:

CDbCommand Object ( [params] => Array ( ) [_connection:private] => OciDbConnection Object 
( [pdoClass] => Oci8PDO [connectionString] => oci:dbname=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=********)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=********)));
[username] => ***** [password] => ******* [schemaCachingDuration] => 0
[schemaCachingExclude] => Array ( ) [schemaCacheID] => cache
[queryCachingDuration] => 0 [queryCachingDependency] => [queryCachingCount] => 0 
[queryCacheID] => cache [autoConnect] => 1 [charset] => [emulatePrepare] => 
[enableParamLogging] => 1 [enableProfiling] => 1 [tablePrefix] => [initSQLs] => 
[driverMap] => Array ( [cubrid] => CCubridSchema [pgsql] => CPgsqlSchema 
[mysqli] => CMysqlSchema [mysql] => CMysqlSchema [sqlite] => CSqliteSchema 
[sqlite2] => CSqliteSchema [mssql] => CMssqlSchema [dblib] => CMssqlSchema 
[sqlsrv] => CMssqlSchema [oci] => COciSchema ) [_driverName:private] => oci 
[_attributes:private] => Array ( ) [_active:private] => 1 [_pdo:private] => Oci8PDO Object ( [_dbh:protected] => Resource id #51 [_options:protected] => Array ( [3] => 2 ) [_isTransaction:protected] => ) [_transaction:private] => 
[_schema:private] => [behaviors] => Array ( ) [_initialized:private] => 1 
[_e:private] => [_m:private] => ) [_text:private] => SELECT 1 FROM dual 
[_statement:private] => [_paramLog:private] => Array ( ) [_query:private] => 
[_fetchMode:private] => Array ( [0] => 2 ) [_e:private] => [_m:private] => ) 

编辑 2:

'db1'=>array(
      'class'=>'ext.oci8Pdo.OciDbConnection',
      'connectionString' => 'oci:dbname=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=**********)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=*******)));',
      'username' => '***',
      'password' => '****',
'emulatePrepare' => true,
      /*
       * enableProfiling and enableParamLogging are working like normal; Default is false.
       */
      'enableProfiling' => true,
      'enableParamLogging' => true,
),

您正在使用 Yii::app()->db 但您的配置文件似乎正在使用 "db1" .你能检查一下吗?这个问题似乎与 Yii 无关,而只是无法连接到正确的数据库系统。

好吧,显然 oci8Pdo.OciDbConnection 在 PHP 5.1 中不起作用,所以我使用了具有正确字符集的 CDbConnection,它运行良好。