Welcome Guest, Not a member yet? Register   Sign In
one codeigniter application folder run two databases
#1

Hi,

I know that it's possible to use a different database on the same connection but i want to use differents databases with differents connections with my CI application.

I have an application for many customers (so one codeigniter application folder), every customer has his own database and his own domain name but all clients need only one application. 

So I want to choose the database according to the domain :
  • domain.com/customer1/ ==> choose connection with database1
  • domain.com/customer2/ ==> choose connection with database2
Thanks for helping me with a solution.
Reply
#2

@morsi,

Here is how you do multiple connections to multiple databases: https://www.codeigniter.com/user_guide/d...-databases

Then all you have to do is when you set your $DB at the top of your model use the ternary option like this
$DB = (site_url() == 'domain1')? $this->load->database('db_connection1', TRUE): $this->load->database('db_connection2', TRUE);
Reply
#3

(05-10-2019, 06:51 AM)php_rocs Wrote: @morsi,

Here is how you do multiple connections to multiple databases: https://www.codeigniter.com/user_guide/d...-databases

Then all you have to do is when you set your $DB at the top of your model use the ternary option like this
$DB = (site_url() == 'domain1')? $this->load->database('db_connection1', TRUE): $this->load->database('db_connection2', TRUE);

Thanks for help but i think i must also change $config['base_url'] into config.php ?

How i can do it ? (Remmembre, i want to use one CI folder and files with many domains and databases)

Thanks.
Reply
#4

Setting your base url in Codeigniter
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB