• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeIgniter keeps returning empty arrays when working with multiple DBs

#1
[eluser]Unknown[/eluser]
I've been searching pretty much every corner of the web regarding this, and have been trying to fix this in every way I've seen described. But it still won't work.

The story: I'm building a basic CMS using CodeIgniter. It uses two databases: one is known beforehand (the main DB) and its connection information is present in config/database.php. The second database is unknown, until a user logs in. The connection information for this DB is fetched from the primary DB (based on the entered login information), stored in the (encrypted and database-based) session object, and used to connect to the secondary database.

Up to now, everything works fine. From the primary DB, the list of user-enabled modules is loaded, but when one of them is clicked (and supposed to load its content, via AJAX, from the secondary DB) it returns an empty array.

Code:
// Fetch the client DB information
$client_db["hostname"] = $this->session->userdata("db_host");
$client_db["username"] = $this->session->userdata("db_user");
$client_db["password"] = $this->session->userdata("db_password");
$client_db["database"] = $this->session->userdata("db_user");
$client_db['dbdriver'] = 'mysqli';
$client_db['dbprefix'] = '';
$client_db['pconnect'] = FALSE;
$client_db['db_debug'] = FALSE;
$client_db['cache_on'] = FALSE;
$client_db['cachedir'] = '';
$client_db['char_set'] = 'utf8';
$client_db['dbcollat'] = 'utf8_general_ci';
$client_db['swap_pre'] = '';
$client_db['autoinit'] = TRUE;
$client_db['stricton'] = FALSE;

$this->db = $this->load->database($client_db, TRUE);

A print_r of $this->db does reveal that the necessary active record child arrays, in this case [ar_select] and [ar_from], are empty. The MySQL query itself, however, has made it into the [queries][0] string.

I honestly don't know what to do about this. If you need any more information, I'll be happy to provide it.

Thanks in advance,

Sam

#2
[eluser]Unknown[/eluser]
Okay, the problem is solved. Slightly embarassing: the secondary database's password had been changed, and somewhere in the process I forgot to reflect this change in the primary database. In my defense: CodeIgniter strangely did not inform me that a connection to the DB could not be made, rather it would just silently return empty stuff.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.