<?php $dbi = new DbMysql; $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); } } } } ?>
原文地址:https://www.cnblogs.com/coffee_cn/p/8994334.html
时间: 2024-10-30 05:17:23