Змінити префікс таблиць modx

Змінити префікс таблиць modx
<?php ini_set("max_execution_time", 0); ignore_user_abort(true); $current_prefix = $modx->config['table_prefix']; function newPre($number) { $arr = array('a','b','c','d','e','f', 'g','h','i','j','k','l', 'm','n','o','p','r','s', 't','u','v','x','y','z', 'A','B','C','D','E','F', 'G','H','I','J','K','L', 'M','N','O','P','R','S', 'T','U','V','X','Y','Z', '1','2','3','4','5','6', '7','8','9','0'); $pass = ""; for($i = 0; $i < $number; $i++) { $index = rand(0, count($arr) — 1); $pass .= $arr[$index]; } return $pass; } $new_prefix = newPre(12).'_'; $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(); } } } echo $new_prefix;
Заповніть бриф, та отримайте приблизну вартість розробки
Бриф на Сайт Бриф на логотип Бриф на друк