×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Ilya Kutalev
Added: Jul 26, 2016 10:15 PM
Views: 4
Tags: no tags
Сбрасывает auto_increment для всех таблиц
  1. $TABLES = FPDO::query("SHOW TABLES", 'array');
  2.  
  3. foreach ($TABLES as $table) {
  4.     $table = $table['Tables_in_u0213848_elite'];
  5.     $values = FPDO::query("SHOW INDEX FROM $table;", 'array');
  6.  
  7.     foreach ($values as $value) {
  8.         if ($value['Key_name'] == 'PRIMARY') $arResult[$table] = $value['Column_name'];
  9.     }
  10.  
  11. }
  12.  
  13. foreach ($arResult as $table => $column) {
  14.     $last = FPDO::query("SELECT `$column` FROM `$table` ORDER BY `$column` LIMIT 1", 'int');
  15.     $arResult[$table] = $last;
  16.     $last = $last + 1;
  17.     FPDO::query("ALTER TABLE `$table` AUTO_INCREMENT = $last;");
  18.     echo "$table очищена<br/>";
  19. }