Message: Configured database connection is persistent. Aborting

喜欢而已 提交于 2019-12-10 13:37:25

问题


Codeigniter 2 to 3 version after upgrading, I get this error.. Why would that be?

An uncaught Exception was encountered

Type: Exception

Message: Configured database connection is persistent. Aborting.

Filename: /var/www/vhosts/xxx.com/app/system/libraries/Session/drivers/Session_database_driver.php

Line Number: 94

Backtrace:

File: /var/www/vhosts/xxx.com/app/application/core/MY_Controller.php Line: 11 Function: __construct

File: /var/www/vhosts/xxx.com/app/application/core/MY_Controller.php Line: 52 Function: __construct

File: /var/www/vhosts/xxx.com/app/application/controllers/Dashboard.php Line: 7 Function: __construct

File: /var/www/vhosts/xxx.com/application/index.php Line: 293 Function: require_once


回答1:


I had the same issue, and found that it was just a matter of changing a setting:

Modify your database.php config file and turn 'pconnect' to false. As part of the CI 3 Framework, it would be part of this array:

$db['default'] = array(
    'pconnect' => FALSE // This value
);

Or if your config file looks more like the CI 2 version:

$db['default']['pconnect'] = FALSE;

A bit of searching seems to suggest that the database doesn't like a persistent connection, possible because of security reasons.




回答2:


Disable caching in database.php file, define caching folder in database.php by

'cachedir' => APPPATH.'cache/db/',

setting and only use

$this->db->cache_on(); 

command where you want your database query being cached.

Don't forget to use

$this->db->cache_off();

after select queries for unwanted cached results.




回答3:


It seems like codeigniter 3.0 doesn't support sessions using database, when persistent is enabled. form: http://www.codeigniter.com/user_guide/libraries/sessions.html?highlight=session#session-preferences

However, there are some conditions that must be met:

Only your default database connection (or the one that you access as $this->db from your controllers) can be used. You must have the Query Builder enabled. You can NOT use a persistent connection. You can NOT use a connection with the cache_on setting enabled.




回答4:


You need to ensure that FALSE goes out without quotes.If you use 'FALSE', the database driver will take that as a true boolean. The system expects you to use FALSE directly, without quotes. So, unset pconnect instead of using 'FALSE' in order to default to FALSE, or use FALSE as a value if you like to keep things ordered :)

 * Persistent connection flag
 *
 * @var bool
 */
public $pconnect        = FALSE;


来源:https://stackoverflow.com/questions/29446898/message-configured-database-connection-is-persistent-aborting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!