Skip to content

Instantly share code, notes, and snippets.

@ig0r74
Created February 18, 2018 21:32
Show Gist options
  • Select an option

  • Save ig0r74/3d454062ef0bdd67a7c3d2ff2b045935 to your computer and use it in GitHub Desktop.

Select an option

Save ig0r74/3d454062ef0bdd67a7c3d2ff2b045935 to your computer and use it in GitHub Desktop.

Revisions

  1. ig0r74 created this gist Feb 18, 2018.
    27 changes: 27 additions & 0 deletions change_prefix.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    <?php
    ini_set("max_execution_time", 0);
    ignore_user_abort(true);

    $current_prefix = $modx->config['table_prefix'];

    $new_prefix = 'My_Prefix234_';

    $stmt = $modx->query("SHOW TABLES");
    $tables = $stmt->fetchAll(PDO::FETCH_NUM);
    $stmt->closeCursor();

    foreach ($tables as $table) {
    $table = reset($table);

    $preg = "/^{$current_prefix}/u";

    if (preg_match($preg, $table)) {
    $new_table_name = preg_replace($preg, $new_prefix, $table);
    $sql = "RENAME TABLE `{$table}` TO `{$new_table_name}`";
    if ($s = $modx->prepare($sql)) {
    $s->execute();
    }
    }
    }

    print "\nTables are updated";