How to test if table was updated in Zend Framework?
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 wou开发者_开发技巧ld 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
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.
精彩评论