CopperRabbit
CopperRabbit

Reputation: 674

CodeIgniter Dynamic DB connection via URL

I need to connect to a DB that's name will be entered in the URL. For Example the URL will be

http://my_url.com/comp/login

So the DB I need to connect to is 'comp'.

Is there a way to do this without defining each database in the database.php config file?

something like

define('COMP', $this -> uri -> segment(1));

and then

'database' => 'tm_'.COMP,

The above gives me an error about the $this, so I am not completely sure where I can define the COMP variable where the database config file can read it.

Thanx

Upvotes: 0

Views: 178

Answers (1)

CopperRabbit
CopperRabbit

Reputation: 674

Was missing this part :

$CI =& get_instance();

and updated the

define('COMP', $this -> uri -> segment(1));

to

define('COMP', $CI -> uri -> segment(1));

is working now

Upvotes: 1

Related Questions