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

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

问题描述

如果我将 CI 应用程序配置为使用数据库进行会话处理,如果会话 userdata 返回 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 会在数据库加载且无法连接时出现致命错误,但如果您有:

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天全站免登陆