我正在尝试使用Code Igniter连接到新数据库,但查询会不断提供上一个数据库的表列表。
我想获取新数据库中的所有表,然后遍历新数据库的表以获取其字段详细信息。
新数据库连接的代码如下
$db['adb']['hostname'] = 'localhost';
$db['adb']['username'] = 'username';
$db['adb']['password'] = 'password';
$db['adb']['database'] = 'database';
$db['adb']['dbdriver'] = 'mysql';
$db['adb']['dbprefix'] = '';
$db['adb']['pconnect'] = TRUE;
$db['adb']['db_debug'] = TRUE;
$db['adb']['cache_on'] = FALSE;
$db['adb']['cachedir'] = '';
$db['adb']['char_set'] = 'utf8';
$db['adb']['dbcollat'] = 'utf8_general_ci';
$db['adb']['swap_pre'] = '';
$db['adb']['autoinit'] = TRUE;
$db['adb']['stricton'] = FALSE;
我的函数代码如下:
$this -> load -> database('adb', TRUE);
$adb = array();
$tables = $this -> db -> list_tables();
foreach ($tables as $table)
{
$temp = array();
$fields = $this -> db -> field_data($table);
$temp['table'] = $table;
$temp['fields'] = $fields;
$adb[] = $temp;
}
我收到错误,指出我的新数据库中不存在表,但原因是该表位于我的旧数据库中,但field_data函数已连接到新数据库
我只希望函数从新数据库中获取表。
提前完成
我的完整数据库配置文件如下所示
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'old_database';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$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;
$db['adb']['hostname'] = 'localhost';
$db['adb']['username'] = 'username';
$db['adb']['password'] = 'password';
$db['adb']['database'] = 'database';
$db['adb']['dbdriver'] = 'mysql';
$db['adb']['dbprefix'] = '';
$db['adb']['pconnect'] = TRUE;
$db['adb']['db_debug'] = TRUE;
$db['adb']['cache_on'] = FALSE;
$db['adb']['cachedir'] = '';
$db['adb']['char_set'] = 'utf8';
$db['adb']['dbcollat'] = 'utf8_general_ci';
$db['adb']['swap_pre'] = '';
$db['adb']['autoinit'] = FALSE;
$db['adb']['stricton'] = FALSE;
答案 0 :(得分:1)