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开发者_如何学Python 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.
精彩评论