为什么Codeigniter3中存在数据库缓存错误?

为什么Codeigniter3中存在数据库缓存错误?,codeigniter,codeigniter-3,Codeigniter,Codeigniter 3,我正在使用Codeigniter 3进行开发,下面是数据库配置的详细信息。我还启用了数据库会话,因此可以在数据库中存储会话数据 这是我的数据库配置 $active_group = 'default'; $query_builder = TRUE; $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'root', 'password' =

我正在使用Codeigniter 3进行开发,下面是数据库配置的详细信息。我还启用了数据库会话,因此可以在数据库中存储会话数据

这是我的数据库配置

$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => '',
    'database' => 'tel',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => TRUE,
    'cache_on' => TRUE,
    'cachedir' =>  '/application/cache',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => TRUE,
    'compress' => TRUE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);
启用会话后,我得到一个异常

An uncaught Exception was encountered

Type: Exception

Message: Configured database connection has cache enabled. Aborting.

Filename: D:\My data\project\wamp\www\fertilize\system\libraries\Session\drivers\Session_database_driver.php

Line Number: 98

Backtrace:

File: D:\My data\project\wamp\www\fertilize\application\core\MY_Controller.php
Line: 11
Function: __construct

File: D:\My data\project\wamp\www\fertilize\application\libraries\Main_Controller.php

我不确定这是什么原因,请帮助。

上述异常不是错误,而是框架内置的Codeigniter 3安全功能。如果您检查system/Session/drivers/Session_database_driver.php,您可以在代码中看到此异常以及一些其他异常

public function __construct(&$params)
{
    parent::__construct($params);

    $CI =& get_instance();
    isset($CI->db) OR $CI->load->database();
    $this->_db = $CI->db;

    if ( ! $this->_db instanceof CI_DB_query_builder)
    {
        throw new Exception('Query Builder not enabled for the configured database. Aborting.');
    }
    elseif ($this->_db->pconnect)
    {
        throw new Exception('Configured database connection is persistent. Aborting.');
    }
    elseif ($this->_db->cache_on)
    {
        throw new Exception('Configured database connection has cache enabled. Aborting.');
    }

    $db_driver = $this->_db->dbdriver.(empty($this->_db->subdriver) ? '' : '_'.$this->_db->subdriver);
    if (strpos($db_driver, 'mysql') !== FALSE)
    {
        $this->_platform = 'mysql';
    }
    elseif (in_array($db_driver, array('postgre', 'pdo_pgsql'), TRUE))
    {
        $this->_platform = 'postgre';
    }
出现异常的原因是,您正在全局使用数据库缓存同时启用会话(存储在数据库中)。通过这样做,会话查询将保存到缓存,从而带来安全风险。您可以通过使用本地数据库缓存来避免这种情况

有关如何使用本地数据库缓存的详细信息,请参见

作为一种良好的实践,请确保在application/cache(application/cache/db)下创建一个文件夹调用db,并将其用于数据库缓存,以将文件缓存与数据库缓存分离


如果您仍然希望保持数据库缓存的全局性,可以使用Redis或Memcache作为会话驱动程序,这将避免数据库中的会话查询并修复您的问题()。

上述异常不是错误,而是框架中内置的Codeigniter 3安全功能。如果您检查system/Session/drivers/Session_database_driver.php,您可以在代码中看到此异常以及一些其他异常

public function __construct(&$params)
{
    parent::__construct($params);

    $CI =& get_instance();
    isset($CI->db) OR $CI->load->database();
    $this->_db = $CI->db;

    if ( ! $this->_db instanceof CI_DB_query_builder)
    {
        throw new Exception('Query Builder not enabled for the configured database. Aborting.');
    }
    elseif ($this->_db->pconnect)
    {
        throw new Exception('Configured database connection is persistent. Aborting.');
    }
    elseif ($this->_db->cache_on)
    {
        throw new Exception('Configured database connection has cache enabled. Aborting.');
    }

    $db_driver = $this->_db->dbdriver.(empty($this->_db->subdriver) ? '' : '_'.$this->_db->subdriver);
    if (strpos($db_driver, 'mysql') !== FALSE)
    {
        $this->_platform = 'mysql';
    }
    elseif (in_array($db_driver, array('postgre', 'pdo_pgsql'), TRUE))
    {
        $this->_platform = 'postgre';
    }
出现异常的原因是,您正在全局使用数据库缓存同时启用会话(存储在数据库中)。通过这样做,会话查询将保存到缓存,从而带来安全风险。您可以通过使用本地数据库缓存来避免这种情况

有关如何使用本地数据库缓存的详细信息,请参见

作为一种良好的实践,请确保在application/cache(application/cache/db)下创建一个文件夹调用db,并将其用于数据库缓存,以将文件缓存与数据库缓存分离


如果您仍然想保持数据库缓存的全局性,可以使用Redis或Memcache作为会话驱动程序,这将避免数据库中的会话查询并解决您的问题()。

简单地说,只需转到
config/database.php
并将
$db['default']['pconnect']=FALSE

简单地说,只需转到
config/database.php
并将
$db['default']['pconnect']=FALSE