<?PHP$DBI=NewDbmysql;$DBI->DBH = ' Mysql://root:[email protected]/coffeetest ';$map=Array();$DBI->fetchmap ("SHOW TABLES",$map);$tables=Array_keys($map); for($i= 0;$i<Count($tables);$i++){ Echo($tables[$i]." \ n "); $sql= "SHOW INDEX from".$tables[$i]; $list=$DBI->fetchall ($sql); $indexs=Array(); foreach($list as $item){ $indexs[$item[' Key_name '] [] =$item[' column_name ']; } $j= 0; $list=Array(); foreach($indexs as $key=$val){ $list[] =Array(' j ' + =$j, ' key ' =$key, ' val ' = =implode(",",$val)); $j++; } $count=Count($list)-1; for($j=$count;$j>=0;$j=$j-1){ $me=$list[$j]; foreach($list as $item){ if($item[' J ']<$me[' J '] &&$item[' Val ']==$me[' Val ']){ Echo("\ T".)$j." \ t ".$me[' Key ']. \ t ".$me[' Val ']. " \ n "); $sql= "ALTER TABLE".$tables[$i]." DROP INDEX ' ".$me[' Key ']. `"; $DBI->execute ($sql); } } }}?>
Support MySQL database management with PHP script 3-delete duplicate table index