开发者

Multiple conditions for db_update

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜