【问题标题】:MySQL Duplicate Entry Creates Internal Server ErrorMySQL 重复条目创建内部服务器错误
【发布时间】:2014-04-29 03:39:23
【问题描述】:

为了避免用户创建重复数据,我在字段上使用了UNIQUE 约束。一切正常,直到重复输入;这立即给了我一个内部服务器错误。我正在使用 CodeIgniter 进行查询并使用 $this->db->_error_message() 检查数据库错误,但程序似乎退出并在我的 AJAX 调用中返回错误号,而不是被处理。 有没有其他方法来处理这些类型的错误,还是我做错了什么?

【问题讨论】:

  • 你可能想发布相关代码。
  • 听起来好像抛出了一个异常,而你忽略了正确捕获它。
  • @CBroe 是什么引发了异常,我该如何处理?
  • 查看您是否在 apache error_log 或您正在使用的任何网络服务器上收到任何错误

标签: php mysql ajax codeigniter unique


【解决方案1】:

插入副本会抛出异常。

试着像这样抓住它:

try
{
    // insertin the duplicate
}
catch (Exception $e)
{
    echo 'Exeption: '.  $e->getMessage();
}

有关异常处理的更多信息:http://www.php.net/manual/en/language.exceptions.php

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-11
  • 1970-01-01
  • 2017-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-05
相关资源
最近更新 更多