CodeIgniter:如何知道$ this-> load-> database();没有连接? [英] CodeIgniter: How to know if $this->load->database(); did connect?

查看:83
本文介绍了CodeIgniter:如何知道$ this-> load-> database();没有连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将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屋!

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