【问题标题】:Codeigniter 3 Query Builder not enabled for the configured database. Aborting. Error未为配置的数据库启用 Codeigniter 3 查询生成器。中止。错误
【发布时间】:2021-10-24 17:24:24
【问题描述】:

我在执行多数据库操作时将会话数据写入数据库环境时遇到错误。 我的数据库配置文件如下;

$active_group = 'default';
$query_builder = TRUE;
$CI = & get_instance();
$CI->load->library('session');

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'ip',
    'username' => 'name',
    'password' => 'pass',
    'database' => 'db',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

$db['db2'] = array(
    'dsn'   => '',
    'hostname' => $CI->session->firma_db_ip,
    'username' => $CI->session->firma_db_kullanici,
    'password' => $CI->session->firma_db_sifre,
    'database' => $CI->session->firma_db,
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

然后我在配置文件中将会话写入数据库的代码如下;

$config['sess_driver'] = 'database';  // select database driver
$config['sess_save_path'] = 'ci_sessions';  // name of the mysql table
$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update']  = 300;

我得到的错误如下;

遇到未捕获的异常类型:异常

消息:未为配置的数据库启用查询生成器。 中止。

文件名: /home/x/domains/x/public_html/x/system/libraries/Session/drivers/Session_database_driver.php

行号:90

回溯:

文件:/home/x/domains/x/public_html/x/application/config/database.php 行:82 功能:库

文件:/home/x/domains/x/public_html/x/index.php 行:315 功能: 需要一次

有人有想法吗?

【问题讨论】:

标签: php mysql codeigniter codeigniter-3


【解决方案1】:

检查 autoload.php 并确保会话库已加载。

$autoload['libraries'] = array('database', 'session');

【讨论】:

    猜你喜欢
    • 2016-08-24
    • 2016-07-25
    • 1970-01-01
    • 2016-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多