未为配置的数据库启用查询构建器

2022-03-31 00:00:00 session php codeigniter codeigniter-3

我使用的是Ci版本3.0.4。 我试图修复这个错误,但没有找到解决方案,所以我在这里发帖 请帮帮忙。 我的配置、常量或控制器文件是否有任何错误? 我的配置文件、常量文件或控制器文件是否有错误。

**Error:** 

An uncaught Exception was encountered

Type: Exception

Message: Query Builder not enabled for the configured database. Aborting.

Filename: G:xamppsoftwarehtdocs24mehtasystemlibrariesSessiondriversSession_database_driver.php

Line Number: 90

**Adminx controller:**

class Adminx extends CI_Controller {

    function __construct() {
        parent::__construct();

        $this->load->module('login');

        $this->load->helper('form');
        $this->output->enable_profiler(ENABLE_PROFILER);
        $this->load->model('Page_DB_Interaction', 'page_db_interaction');
        $login = new Login();
        if (!$login->_is_logged_in()) {
            $citer = &get_instance();
            $url_page = $citer->uri->segment(1);
            $this->session->set_userdata('url_page', $url_page);
            $this->session->set_userdata('login_page', 'backend');
            redirect('login');
        }
    }

**Autoload file:**
$autoload['libraries'] = array('database');
$autoload['drivers'] = array('session');

**login controller**

class Login extends CI_Controller {

    function __construct() {

        parent::__construct();

        $this->load->helper('directory');
        $this->load->helper('cookie');
        $this->load->model('Global_model', 'gm');


    }

**config file:**
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'easfsession';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'NULL';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

I am using ci version '3.0.4'

解决方案

检查文件/application/config/database.php并确保$query_builder = TRUE;我猜它当前设置为False。

我还建议将session作为库而不是驱动程序加载。

$autoload['libraries'] = array('database', 'session');
//remove this line
//$autoload['drivers'] = array('session'); 

在会话配置中使用

$config['sess_save_path'] = 'ci_sessions'; //assumes `ci_sessions` is the table name you are using

相关文章