如何测试 Zend Framework 中的表是否已更新?
当用户打开表单来修改记录时,他只需单击“更新”按钮,而不是更改信息。这会导致 update() 函数返回 0。但是,我认为这种情况是有效的更新任务。我将如何测试它,以便我可以分配成功消息?
SQL查询失败时update()返回-1还是0?
方法: Zend_Db_Table_Abstract::update()
有什么想法吗?
谢谢
When user opens a form to modify a record, but instead of changing information, he just clicks the Update button. Which causes the update() function to return 0. However, I consider this case a valid update task. How would I test it, so I can assign a success message?
Is update() returns -1 when SQL query failed or also 0?
Method: Zend_Db_Table_Abstract::update()
Any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Zend_Db 只能返回 MySQL 适配器可以返回的内容。这将是更新的行数。但是,如果查询出错,它确实会引发异常。因此,最好的选择是将更新语句包装在 try/catch 中。如果它捕获异常,则在您的应用程序中显示错误。如果没有,则认为查询正确执行,即使没有更新数据。
Zend_Db can only return what the MySQL adapter can return. Which would be the number of rows updated. However it does throw an exception in the event that a query errors out. So your best bet would be to wrap your update statement in a try/catch. If it catches an exception, then display an error in your application. If it does not, then consider the query executed correctly, even if no data was updated.