Codeigniter2在错误的数据库上执行查询.. bug?

时间:2018-06-28 19:42:54

标签: php codeigniter codeigniter-2

我非常了解CodeIgniter 2,现在我在一个现有项目中遇到了一个奇怪的错误,我无法弄清楚。

$this->db->flush_cache();    // Just to be sure
echo $this->db->database;    // Displays "database_A"
$query = $this->db->get('table_X');

然后我得到了错误:

A Database Error Occurred
Error Number: 1146
Table 'database_B.table_X' doesn't exist
SELECT * FROM (`table_X`) WHERE `account_name` = 'bob'
Filename: /home/naturbl9/public_html/app/models/my_model.php
Line Number: 132

您可以清楚地看到,回显当前使用的数据库将显示“ database_A”,但是CodeIgniter尝试在“ database_B”中执行查询,该查询在其他地方使用(并以其他名称使用!而不是“ db”) ”)。如果将“ pconnect”设置为false,则不会发生此问题。

database.php配置:
(使用相同的配置但将$ db ['default'] ['database']动态更改为“ database_B”来加载database_B):

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database_A';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE; // If set to false, the bug doesn't occur!
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

0 个答案:

没有答案