Yii Dao

Steps to operate the database using php:

First, open the database connection:mysql_connect();

Second, Open Table:mysql_select_db();

Third, implementation of the SQL statement:mysql_query();

Finally close the connection:mysql_close();

We use the same principle Yii Dao:

$connection = new CDbConnection($dsn,$username,$password);

$connection->active = true;

$connection->active = false;

Now I do not instantiate CDbConnection,But the use of Yii components "db";

$connection = Yii::app()->db;

I would like to know whether I should close the connection after completing the operation!

I need to use " $connection->active = false; " ?

I view the source code of Yii about CDbConnection and RA.

I found Yii operation of the database using the RA, when completed, did not close the database connection.

I mean yii do not use " $connection->active = false; ";

This looks like?

Is there a example about Yii dao?

I met the same problem.

Forget about creating a new instance of CDbConnection. The example in the docs is rather meant for a standalone application where you don’t have a configuration.

All you have to do:

  • configure the db component in your main.php configuration

  • access the connection through Yii::app()->db

No need to activate or close this connection. If you really need to close the connection manually you could add this to your index.php: