1 ...
1 <?php 2 set_time_limit(0); 3 $con = mysql_connect("localhost", "root", "root"); 4 $dbname = "db"; 5 if ($con) { 6 if (mysql_select_db($dbname, $con)) { 7 $sql = "show tables like 'pre_tb_%'"; 8 $ret = mysql_query($sql); 9 while($row = mysql_fetch_assoc($ret)){ 10 $info1[] = $row; 11 } 12 foreach ($info1 as $v) { 13 $chidarr1[] = substr($v['Tables_in_multiopen (pre_tb_%)'],7);//獲取標記號 14 } 15 foreach ($chidarr1 as $val) { 16 $tabname = 'stat_adclick_'.$val; 17 $sql = "alter table $tabname add column c2 int default 0 after p"; 18 mysql_query($sql); 19 $sql = "alter table $tabname DROP PRIMARY KEY"; 20 mysql_query($sql); 21 $sql = "alter table $tabname add primary key(c2,p)"; 22 mysql_query($sql); 23 $sql = "alter table $tabname drop index old_index"; 24 mysql_query($sql); 25 $sql = "create index idx_newincex on $tabname (c2,p)"; 26 mysql_query($sql); 27 } 28 } 29 } 30 mysql_close($con); 31 ?>