Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to do something relatively simple but can't figure it out.

I just want to add to a current value in the DB is there anyway to do the equivalent of a:

UPDATE `tablename` SET fieldB = fieldB + 1 WHERE fieldA='X'

Using the Zend/db update function?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

it will be something like this:

 $select = $sql->update();
 $select->table('basket');
 $select->set(array(
      'quantity' => new \Zend\Db\Sql\Expression("quantity - ".((int)$quantity))
 ));
 $select->where(array('basket_id'=>$basket_id));

Of course, if it will not be numbers you need to escape.

share|improve this answer
 
Thank you Tomek! do you by any chance know where I can find a good list of examples/documentation with regards to Zend/db queries? I find this to be somewhat lacking on the docs. –  Juan Jun 26 '13 at 13:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.