用于删除的db_query在PHP代码中不起作用,但直接在mysql

时间:2017-09-18 12:46:50

标签: mysql drupal-6

当我在我的网站上运行此脚本时,它不会删除任何行,即使输出显示查询成功(它现在输出写出的删除查询)。当我直接在mysql中运行查询时,它会删除行。

    if (db_query("DELETE FROM {watchdog} WHERE ((type = 'user' AND message IN ('Session opened for %name.', 'Session closed for %name.', 'New user: %name (%email).')) OR type = 'access denied' OR (type = 'smtp' AND message = 'Sending mail to: @to')) AND hostname = '%s'", array($hostname)))
    {
      echo "<br />DELETE FROM watchdog WHERE ((type = 'user' AND message IN ('Session opened for %name.', 'Session closed for %name.', 'New user: %name (%email).')) OR type = 'access denied' OR (type = 'smtp' AND message = 'Sending mail to: @to')) AND hostname = '$hostname'";
    }
    else
    {
      echo "<br />could not delete $hostname ";
    }

屏幕或任何日志中都没有错误消息。

1 个答案:

答案 0 :(得分:0)

原来我必须逃脱百分号

 ('Session opened for %name.', 'Session closed for %name.', 'New user: %name (%email).')) 

变为

 ('Session opened for %%name.', 'Session closed for %%name.', 'New user: %%name (%%email).'))