db_update 的多个条件
在 Drupal 7 中,简单的更新工作如下:
$num_updated = db_update('joke')
->fields(array(
'punchline' => 'Take my wife please!',
))
->condition('nid', 3, '>=')
->execute();
但是如果我有多个条件(比如 nid >=3 和 uid >=2)怎么办?写类似:
$num_updated = db_update('joke')
->fields(array(
'punchline' => 'Take my wife please!',
))
->condition('nid', 3, '>=')
->condition('uid', 2, '>=')
->execute();
似乎不起作用。有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所编写的内容相当于:
如果您想要一个 OR 条件,您需要这样嵌套语句(不,这不是很直观):
还有 db_and() [链接多个条件方法的默认值] 和 db_xor( ),您可以在嵌套时使用。
What you have written will do the equivalent of:
If you wanted an OR conditional you need to nest the statements as such (no, it's not very intuitive):
There is also db_and() [default for chaining multiple condition methods] and db_xor() that you can use when nesting.