• php批量修改表结构


     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 ?>
  • 相关阅读:
    LeetCode 101. 对称二叉树
    PTA 两个有序序列的中位数(25分)
    CF1567
    亚线性筛
    LowbitMatrix(线段树)
    Matrix(组合数学)
    [模版] 数论基础模版
    Gym102001
    Gym102483A
    [模版] Miller-Rabin素性测试&Pollard-Rho分解质因数
  • 原文地址:https://www.cnblogs.com/Crius/p/6894768.html
Copyright © 2020-2023  润新知