[eluser]Katie1348[/eluser]
[quote author="jonkenedi" date="1354330680"][quote author="WanWizard" date="1282560730"]You don't need to resort to manual coding, just use the database library to connect to multiple databases.
In your config/database.php, create a default entry for your 'app' database. You can connect to that database using
Code:
$this->load->database();
And access it using
For your user databases, you could simply add a section to config/database.php, assuming that you have some process in place to create these databases for these users:
Code:
$db['userA']['hostname'] = '...';
// and so on
You can then connect to it using
Code:
// this will make the connection globally available
$CI =& get_instance;
$CI->userdb = $this->load->database('userA', TRUE);
$this->userdb =& $CI->userdb;
If you can't/won't have these userdb configurations in the config file, you can also generate the config array at runtime:
Code:
$db = array();
$db['hostname'] = '...';
// and so on
// connect to the database
$CI =& get_instance;
$CI->userdb = $this->load->database($db, TRUE);
$this->userdb =& $CI->userdb;
[/quote]
Hay WanWizard...
I have try but i get error Us
ing $this when not in object context and...
Code:
// I change $this = $CI... this my config
$CI =& get_instance;
$CI->userdb = $CI->load->database($db, TRUE);
$CI->userdb =& $CI->userdb;
i get error
Fatal error: Allowed memory size of... [/quote]
Incase it helps anyone else coming to this topic, there is a typo in the code.
It should read:
Code:
// I change $this = $CI... this my config
$CI =& get_instance();
$CI->userdb = $CI->load->database($db, TRUE);
$CI->userdb =& $CI->userdb;
The change is that get_instance is a method and needs the ().
K