I am trying to connect to a new database with Code Igniter, but the query keeps giving the table list of the previous Database.
I want to get all the tables in the new DB, then loop through the new DB's tables to get their field details.
my code is as follows for the new DB connection
$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;
My function's code looks like this:
$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;
}
I get the error stating that a table does not exist in my new database, but the reason for this is the table is in my old DB, but the field_data function is connected to the new DB
I only want the function to get the tables from the new DB.
Thanx in advance
My complete Database config file looks like this
$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;