CodeIgniter通过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
我需要连接到一个名称将在URL中输入的数据库。 例如,URL将是 nn
http://my_url.com/comp/login
我需要连接的数据库是'comp '。 p>
有没有办法在不定义database.php配置文件中的每个数据库的情况下执行此操作? p>
类似 p> \ n
define('COMP',$ this - > uri - > segment(1));
code> pre>
然后
'database'=> 'tm _'。COMP,
code> pre>
上面给出了一个关于$ this的错误,所以我不能完全确定在哪里可以定义COMP变量所在的数据库 配置文件可以读取它。 p>
Thanx p>
div>
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