Skip to content

Instantly share code, notes, and snippets.

@andronex
Created October 15, 2025 18:50
Show Gist options
  • Save andronex/088a2664c4235cb392058e2c7123b72b to your computer and use it in GitHub Desktop.
Save andronex/088a2664c4235cb392058e2c7123b72b to your computer and use it in GitHub Desktop.
Массовое переименование таблиц БД MySQL с помощью PHP прямо из консоли MODX. После отработки скрипта изменить в конфиге префикс таблиц вручную.
<?php
$db = $modx->getManager()->xpdo->pdo;
// Получаем список таблиц
$tables = $db->query("SHOW TABLES LIKE 'mt_%'")->fetchAll(PDO::FETCH_COLUMN);
foreach ($tables as $table) {
$new_table = str_replace('mt_', 'lr_', $table);
$sql = "RENAME TABLE `$table` TO `$new_table`";
try {
$db->exec($sql);
echo "Переименовано: $table -> $new_table\n";
} catch (PDOException $e) {
echo "Ошибка при переименовании $table: " . $e->getMessage() . "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment