Avoid opening DB connection if no query

Hi All,

I have a yii website but always has MySql error: exceeded the ‘max_connections_per_hour’ resource (current value: 20000)

I was used file cache for any db query, but when i check the trace, still have "Opening DB connection" from system.db.CDbConnection.

How to don’t open connection if no query? Any suggestion?

Thanks a lot! :)

You must access your db somewhere. Like all other components the db component is only created when it is used. Maybe you configured CDbHttpSessions as session component? Or do you use RBAC and save your hierarchy in DB? Check the logs, to find out which queries are sent to the database.

One more thing to add to the Mike answer… could be that you have a dependency for the cache to check if the cache is still valid… so to evaluate this dependency, again a call to the database should be made…

Thanks Mike & mdomba

I finally find out the root case, it’s because my data value is NULL,

for example i has a table:

My script in controller:

When i check trace info, still have db connection, but when the subject value is not null or change the subject is not allow null on the db table, it’s no db connection…

It’s a bug or I doing some wrong?