CodeIgniter:如何知道$ this-> load-> database();没有连接? [英] CodeIgniter: How to know if $this->load->database(); did connect?
问题描述
如果我将CI应用程序配置为使用数据库进行会话处理,则如果会话用户数据返回false,则可以假设用户的会话已过期。
If I configure my CI application to use database for session handling, if a session userdata returns false, I can assume that the user's session has expired.
如果返回false的实际原因是因为数据库连接未成功建立?
But what if the actual reason that it returned false was because the database connection was not established successfully?
推荐答案
默认情况下CodeIgniter会致命错误if数据库加载无法连接,但如果您有:
By default CodeIgniter will fatal error if the database is loaded and cannot connect, but if you have:
$db['local']['db_debug'] = FALSE;
那么它不会告诉你。您可以在一般情况下关闭调试功能,但仍然会对失败的负载做出反应:
then it won't tell you. You can turn debugging off in general but still react to a failed load by doing this:
if ( $this->load->database() === FALSE )
{
exit('THE END IS NIGH!');
}
这篇关于CodeIgniter:如何知道$ this-> load-> database();没有连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!