In Drupal 7 simple updates work like this:
$num_updated = db_update('joke')
->fields(array(
'punchline' => 'Take my wife please!',
))
->condition('nid', 3, '>=')
->execute();
But what if I have multiple conditions( say nid >=3 and uid >=2). Writing something like:
$num_updated = db_update('joke')
->fields(array(
'punchline' => 'Take my wife please!',
))
->condition('nid', 3, '>=')
->condition('uid', 2, '>=')
->execute();
does not seem to work. Any ideas?
What you have written will do the equivalent of:
'...WHERE (NID >= 3 AND UID >= 2)"
If you wanted an OR conditional you need to nest the statements as such (no, it's not very intuitive):
->condition(db_or()->condition('NID'', 3, '>=')->condition('UID', 2, '>='))
There is also db_and() [default for chaining multiple condition methods] and db_xor() that you can use when nesting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With