Tony Bogdanov
Tony Bogdanov

Reputation: 7686

Zend_Db -> update() increments my values twice?

I have a pretty weird problem related to zend framework's zend_db.

I use

$this -> update(array('visits' => new Zend_Db_Expr('`visits` + 1')), new Zend_Db_Expr("`ip` = '{$ip}' AND `day` = {$day} AND `month` = {$month} AND `year` = {$year}"));

to increments visits with 1. The problem is that Zend increments it with value * 2, in this case 2, if I say visits + 5, it then increments with 10?!!

It is really strange, since the pure SQL works. I've tried going to the code of the Update() function, then I just say exit($sql) and I can see that the SQL is ok, it runs properly under phpMyAdmin, except when I let update() run.

I thought I might call update() twice somewhere, so I've put exit(); in it, so it would break after running once... same problem...

Thanks in advance!

Btw, my zend framework is 1.11.11 or less.

Upvotes: 0

Views: 1144

Answers (1)

aporat
aporat

Reputation: 5932

what happens if you write it as a standard sql update, without the zend_db_table's update() function? does it work as expected ?

$this->_db->query('UPDATE ' . $this->_name . ' SET visits = visits + 1 WHERE ip = ? AND `day` = ? AND `month` = ? AND `year` = ?", array($ip, $year, $month, $day);

If it does work correctly, it means there's something wrong with the update() function. If it's still an issue, you might running the script twice somehow.

Also, does your class extend directly from Zend_Db_Table_Abstract? I had some cases that the update function was override with a different logic.

Upvotes: 2

Related Questions