9

When I try to connect to my database, everything is ok, but when I try to use the query() command to execute a SQL statement I get this error:

The connection was reset

The connection to the server was reset while the page was

The page doesn't load.

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

I'm trying to do this in the index.php page, if I comment the last line, the page load successfully.

I tested the connection with echo isset(Yii::app()->db); and I got 1.

I'm using oci8Pdo.OciDbConnection class.

EDIT:

print_r($command) result:

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] => ) 

EDIT2:

'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,
),
13
  • query() will give you only the text of your query, you have to use queryAll() function Apr 21, 2015 at 4:21
  • I used queryAll() too.. same problem... Apr 21, 2015 at 8:12
  • you haven't included your database connection config, maybe there's the problem Apr 21, 2015 at 8:42
  • $oci=Yii::app()->db; is working... I can var_dump it if you want. Apr 21, 2015 at 8:47
  • I edited the post with some debug code Apr 21, 2015 at 10:05

2 Answers 2

3

well, apparently the oci8Pdo.OciDbConnection doesn't work in PHP 5.1 so I used CDbConnection with the right charset and it worked well.

2
  • 1
    You're using PHP 5.1?! The last release was 9 years ago and there have been many, many security fixes since then. Your server must be utterly unsecure. Please do yourself (as a developer) and the internet (by not running vulnerable out-of-date software) a favour and update to the latest PHP!
    – timclutton
    Apr 28, 2015 at 8:02
  • It's an ethernet based app for a company. Update the php to the latest version will cost some hours to modify the atual php app. But I agree with you and I appreciate your concern. Apr 28, 2015 at 12:03
1

You are using Yii::app()->db but your configuration file seems to be using "db1". Can you check it? This problem does not seem to be related to Yii, but simply an inability to connect to the right database system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.