dqluw20882 2016-09-16 15:02
浏览 45
已采纳

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

  • 写回答

1条回答 默认 最新

  • dsf1222 2016-09-16 15:08
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据