Hacker News new | ask | show | jobs
by reustle 2643 days ago
A developer at Pipdig wrote these lines of code and shipped it, I wonder how they felt.

    foreach ($tables as $table) {
        $wpdb->query("DROP TABLE $table");
    }
2 comments

Feels right to remind people to keep backups :P
While I don't disagree that this is horrible, perhaps the $tables array is hardcoded array.

  global $wpdb;
  $prefix = str_replace('_', '\_', $wpdb->prefix);
  $tables = $wpdb->get_col("SHOW TABLES LIKE '{$prefix}%'");
  foreach ($tables as $table) {
   $wpdb->query("DROP TABLE $table");
  }
Essentially for those who aren't familiar with WordPress databases - this drops all tables relating to the WordPress install
It is not, you can check the post for the full context.
Or, better still, an Archive.org snapshot of the commit that added this very code: https://web.archive.org/web/20190331195338/bitbucket.org/pip...

(As a resident geek, I was asked to look into this by a friend)

For good measure, the commit seems to be removed from the original repo.
It's pretty much the same as if it was hardcoded, it drops all tables that have a name starting with the WP prefix. It's extremely ugly, but it's not unsafe (if your plan is removing all WP related tables from the DB).