Zend_db 更新更好的错误报告 [英] Zend_db update better error reporting

查看:35
本文介绍了Zend_db 更新更好的错误报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新记录时,我使用更新"的结果来确定它是否正常工作.

When I update a record, I'm using the result from 'update' to determine if it worked correctly.

$a = $this->db->insert(self::TABLE, $saveData);

$a = 1 表示它更新了一条记录.$a = 0 表示它没有更新任何东西.如果表格没有任何变化,我可以得到 0.但我也假设如果出现错误,我可以得到 0.

$a = 1 means that it updated one record. $a = 0 means that it didn't update anything. I can get a 0 if there was nothing changed in the form. But I also assume I can get a 0 if there was an error.

我希望能够告诉用户信息没有更新是因为他们没有改变任何东西或者存在某种实际错误.

I'd like to be able to tell the user that the information was not updated because they didn't change anything or that there was an actual error of some sort.

错误返回 0 还是返回 -1 我是否正确?

Am I correct that an error returns 0 or does it return -1?

每当我试图产生错误来检查这一点时,我得到的只是一个 Zend 错误,它没有吸引力,坦率地说,相当无用.

When ever I try to produce an error to check this, all I get is a Zend error that's not attractive and frankly rather un-useful.

推荐答案

如果查询因服务器错误、格式错误或无效数据而失败,您将收到异常而不是返回值.所以要做你想做的事,你可以做这样的事情:

If the query failed due to a server error, or malformed query or invalid data, you will get an exception as opposed to a return value. So to do what you want, you can do something like this:

try {
    $a = $this->db->insert(self::TABLE, $saveData);

    if ($a == 0) {
        // return no data was updated
    } else {
        // return data was updated
    }
} catch(Zend_Exception $ex) {
    // query did NOT execute successfully
    // call $ex->getMessage() for the actual error
    // return failure result
}

这篇关于Zend_db 更新更好的错误报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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