Created
October 15, 2025 18:50
-
-
Save andronex/088a2664c4235cb392058e2c7123b72b to your computer and use it in GitHub Desktop.
Массовое переименование таблиц БД MySQL с помощью PHP прямо из консоли MODX. После отработки скрипта изменить в конфиге префикс таблиц вручную.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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