CodeIgniter连接db自定义错误

时间:2012-04-16 06:12:17

标签: codeigniter codeigniter-2

我有这个代码

    $specific['hostname'] = "localhost";
    $specific['username'] = "root";
    $specific['password'] = "";
    $specific['database'] = "ci_forsyria";
    $specific['dbdriver'] = "mysql";
    $specific['dbprefix'] = "";
    $specific['pconnect'] = FALSE;
    $specific['db_debug'] = FALSE;
    $specific['cache_on'] = FALSE;
    $specific['cachedir'] = "";
    $specific['char_set'] = "utf8";
    $specific['dbcollat'] = "utf8_general_ci";

$specific_db = $this->load->database($specific, TRUE);

我使用此参数“FALSE”来隐藏连接错误!

$specific['db_debug'] = FALSE;

但如果我可以创建自定义错误消息,如果连接字段

$ connect = $ this-> db-> connect;     如果(!$连接)     {         //打印错误信息..     }

1 个答案:

答案 0 :(得分:0)

DB_Debug旨在显示数据库错误消息。

您已将该功能关闭为“$ specific ['db_debug'] = FALSE;”

所以你需要重新打开它,并在error_db.php文件上过滤$ error消息。

即。在error_db.php里面

 <? php if ($message === 'Database connection error')
         {
               echo $message;
         }
         else
         {
               echo "error - sorry";
         } ?>

或类似的东西