7

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?

1 Answer 1

7

it will be something like this:

 $select = $sql->update();
 $select->table('basket');
 $select->set(['quantity' => new Expression("quantity + ? ", [$quantity])]);
 $select->where(['basket_id'=>$basket_id]);

Remember to escape/sanitize your data! (like i do with $quantity)

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.