CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: CodeIgniter how to connect multi database using database.php for first connection and Model for second connection (/showthread.php?tid=50955) Pages:
1
2
|
CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - El Forum - 04-14-2012 [eluser]dev.bashar[/eluser] Hello I have many database connection i have primary connection in the database.php file $active_group = 'default'; $active_record = TRUE; Code: $db['default']['hostname'] = 'xxx'; and i have many more connections .. but i must to config another connections using Model can i pass parameters to database.php? or can i put like this code in Model Code: $db['xxx']['hostname'] = 'xxx'; $this->load->database('xxx', TRUE); CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - El Forum - 04-15-2012 [eluser]zay yar phone[/eluser] Yes, You can load new database connection as follows, and assign to variable. Code: $remote = $this->load->database(‘xxx’, TRUE); CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - El Forum - 04-15-2012 [eluser]dev.bashar[/eluser] no i have 100 database and i want to connect from the Model for this database not from the database.php only the main database in from database.php CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - El Forum - 04-15-2012 [eluser]zay yar phone[/eluser] do you mean 1 Model -> 1 database, Where do you get the database name dynamically. datbase name same as model name?' Other database configurations for 100 database are same, such as (hostname,username,password)? CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - El Forum - 04-15-2012 [eluser]dev.bashar[/eluser] no i mean i have main database and in this main database there is the configuration settings to another database i have some project that every user have different database .. now the main database configuration in database.php but now i must to check the user login From model and connect to his database thank you for help CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - El Forum - 04-15-2012 [eluser]zay yar phone[/eluser] If I understand you correctly 1) database configuration settings for 100 databases are stored in the main database. 2) Users are authenticated using the main database. 3)Once the users are authenticated you have to figure out the their respective database to connect to. In the authentication process store the user specific database name into the PHP $_SESSION['db_name'] = 'db1'; // db1 is the databasename Write the My_Model which extends the CI_Model. Store MY_Model into the ./applications/core/ In the Constructor of My_Model class establish the database connection dynamically. Code: $specific['hostname'] = 'xxx'; All finally all your Model class extends the MY_Model. Code: // in certain case which you want to connect to the main database in between CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - El Forum - 04-15-2012 [eluser]dev.bashar[/eluser] it's not work i see the manual connect in CI docs but it's not working must i call any function to switch between tow database? thank you for help again but i am really need this code CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - El Forum - 04-15-2012 [eluser]dev.bashar[/eluser] i insert this code in my Model but he didn't print any error message and the connection still in main database CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - El Forum - 04-15-2012 [eluser]zay yar phone[/eluser] These will help you debug, Code: // 1) call this after the user is logged-in. Check if the $_SESSION['db_name'] is stored properly. CodeIgniter how to connect multi database using database.php for first connection and Model for second connection - El Forum - 04-15-2012 [eluser]zay yar phone[/eluser] can you send me the code of MY_Model.php which is stored in the ./application/core. |