codeigniter mysql 挂掉_處理codeigniter mysql插入中的重復鍵

What I want to do is something like this:

我想做的是這樣的:

function registerUser($username, $password){

$this->db->insert('tblUsers', array('username'=>$username, 'password'=>md5($password)));

if($this->db->_error_number()==1062){

return "DUPLICATE";

}

return true;

}

However, at the moment if there is a duplicate key then its not letting me get to the _error_number() bit. Its displaying an error like this:

但是,如果有一個重復的密鑰,那么它不會讓我到達_error_number()位。它顯示如下錯誤:

c8a663a891394be445a2df2eb7cf18ad.jpe

How do I stop codeigniter from bailing with an error and passing the error number to me to deal with appropriately?

如何讓codeigniter停止出錯並將錯誤號傳遞給我以便妥善處理?

Thanks

謝謝

2 个解决方案

#1

12

You can access MySQL error messages in Codeigniter using:

您可以使用以下命令訪問Codeigniter中的MySQL錯誤消息:

$this->db->_error_message();

Apparently DB_DEBUG needs to be set to false in the database config file:

顯然,數據庫配置文件中需要將DB_DEBUG設置為false:

Ensure DB_DEBUG is set to FALSE in the database config file, or execution will halt when a mysql error occurs (it does not get thrown, it justs exits from the php interpreter)

確保DB_DEBUG在數據庫配置文件中設置為FALSE,否則執行將在發生mysql錯誤時停止(它不會被拋出,它只是從php解釋器退出)

鏈接:http://codeigniter.com/forums/viewthread/79950/#413830

#2

8

Suggestion:

建議:

$orig_db_debug = $this->db->db_debug;

$this->db->db_debug = FALSE;

RUN QUERY HERE

$this->db->db_debug = $orig_db_debug;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值