2009年10月31日星期六

Re: [fw-db] weird Zend_Db_Table_Abstract behaviour

The result is successful. Update returns the number of affected rows. IF
there is nothing to update it will retun 0 which is going to eval to false.
IF something goes wrong in the query its going to throw an exception, not
return false.

if you want to check that the qurey went through then wrap your update in a
try catch and return false in the catch.

If on the other hand you are expecting to at least have one row modified
then you can test agianst > 0.


nulele wrote:
>
> Hello,
> I don't know why, but when I call the method below and there's nothing to
> update (datas are not changed) it returns false... I mean is this normal?
> Even if datas are not changed I would expect a successful result of the
> update operation... it simply would update nothing!!
>
> class Model_DbTable_Users extends Zend_Db_Table_Abstract
> {
> protected $_name = 'users';
> protected $_primary = 'id_user';
>
> ....
>
> public function updateData($data, $id)
> {
> $id = (int)$id;
> if($this->update($data, "id_user = " . $id))
> {
> return true;
> }
> return false;
> }
>
> ...
>
> }
>
> Maybe the problem could be NOT NULL fileds in the db?
> I know, would be better to include the update code in a try/catch
> statement, but I want to hear your opinion on this weird behaviour.
>
> Thanks
>

--
View this message in context: http://old.nabble.com/weird-Zend_Db_Table_Abstract-behaviour-tp26136108p26148578.html
Sent from the Zend DB mailing list archive at Nabble.com.

没有评论: