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

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

报告相同问题?

悬赏问题

  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?
  • ¥15 Java+vue部署版本反编译