Codeigniter在运行时更改数据库配置 [英] Codeigniter change database config at runtime

查看:99
本文介绍了Codeigniter在运行时更改数据库配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在控制器中更改每个方法的数据库配置吗?

Can I change the database config per method in a controller?

$db['default']['db_debug'] = TRUE;

默认值为 TRUE 在某个方法中使其为false,以捕获错误并执行其他操作(例如显示404页面)。

The default is TRUE, while I need to make it false in a certain method to catch the error and do something else (for example show 404 page).

当我尝试 $ this

When I tried $this->config->load('database') it fails.

另一个问题:

我可以检查一个不正确的查询并捕获它到一些变量,而不是显示给用户除了将 db_debug 配置为 FALSE

Can I check an incorrect query and catch it to some variables rather than displaying it to users other than setting the db_debug config to FALSE?

推荐答案

我检查了system / database / DB_Driver的代码,发现: p>

I checked the code of system/database/DB_Driver and found that:

$this->db->db_debug = FALSE;

将在我的控制器中启用/禁用即时调试。

will work in my controller to enable/disable the debug thing on the fly.

这篇关于Codeigniter在运行时更改数据库配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆