2

我正在尝试执行类似“DELETE FROM ac_journal_term WHERE jid = $jid AND tid = $tid”的查询;

foreach ($form_state["values"]["existing_tags"] as $tid)
{
  db_delete('ac_journal_term') 
  ->condition('jid', $jid)->condition('tid', $tid)
  ->execute();
}

我认为这不是正确的方法,但我在网上找不到关于如何使用 db_delete 执行多个条件的示例。

4

4 回答 4

3

db_delete 遵循通常的条件约定。

foreach ($form_state["values"]["existing_tags"] as $tid)
{
  $and = db_and()->condition('jid', $jid)->condition('tid', $tid);
  db_delete('ac_journal_term') 
  ->condition($and)
  ->execute();
}

请参阅此处的条件子句文档:

https://drupal.org/node/310086

于 2013-11-06T01:08:46.293 回答
1

这是 block.module 中的一个示例:

/**
 * Implements hook_menu_delete().
 */
function block_menu_delete($menu) {
  db_delete('block')
    ->condition('module', 'menu')
    ->condition('delta', $menu['menu_name'])
    ->execute();
  db_delete('block_role')
    ->condition('module', 'menu')
    ->condition('delta', $menu['menu_name'])
    ->execute();
}
于 2014-05-23T10:06:06.543 回答
0

Drupal 的做法是——

db_delete('ac_journal_term') ->condition('jid', $jid) ->condition('tid', $tid) ->execute();

于 2015-04-01T06:07:38.050 回答
-1
<?php
  foreach ($form_state["values"]["existing_tags"] as $tid){
    $and = db_and()->condition('jid', $jid)->condition('tid', $tid);
    db_delete('ac_journal_term')->condition($and)->execute();  
  }
    // Above translates to:
   DELETE FROM {ac_journal_term}  WHERE ( (jid = $jid) AND (tid = $tid) )
?>

如果您需要更多详细信息,请参阅以下链接。 关联

于 2013-11-06T09:02:54.130 回答