Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Deleting a comment is not as simple as deleting a row from the database. I wrote this sippet a while ago to delete <em>all</em> comments from a Drupal 5 site:</p> <pre><code>&lt;?php $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid'); while ($comment = db_fetch_object($result)) { $comment-&gt;name = $comment-&gt;uid ? $comment-&gt;registered_name : $comment-&gt;name; _comment_delete_thread($comment); _comment_update_node_statistics($comment-&gt;nid); } ?&gt; </code></pre> <p>It's based on the code in <a href="http://api.drupal.org/api/drupal/modules--comment--comment.module/function/comment_delete/5" rel="nofollow">comment_delete()</a> and <a href="http://api.drupal.org/api/drupal/modules--comment--comment.module/function/comment_confirm_delete_submit/5" rel="nofollow">comment_confirm_delete_submit()</a> and makes sure that all relevant actions like invoking hooks and updating statistics are performed. In your case, you would have to add a where clause to the query to make sure you're only deleting the old comments.</p> <p>Depending on the performance of your server and the number of comments you have to delete, you may want to add a <a href="http://php.net/manual/en/function.set-time-limit.php" rel="nofollow">set_time_limit()</a> in the while block to prevent a php timeout.</p> <p>This code snippet can be run from a custom module, but you can also install Devel module and run the code from it's 'execute php' block.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload