zoukankan      html  css  js  c++  java
  • thinkphp扩展 根据前端批量建立字段

    /*批量添加字段辅助*/
        function add_colum($tabel){
            foreach ($_POST as $key=>$value){    
                $array[] = "add ".$key." varchar(220),";
            }
            $sql_column = "select count(*) count from information_schema.COLUMNS where table_name='".$tabel."' and COLUMN_NAME = '".$key."'";
            $colum = M();
            $colum_count = $colum->query($sql_column);
            $count = $colum_count['0']['count'];
            if($count == 0){
                $string=rtrim(implode(" ",$array), ",");
                $sql="alter table ".$tabel." ".$string."";
                $addcolum = M();
                $go = $addcolum->query($sql);
            }
        }

    用法:$this->add_colum('db_self'); 批量建立完字段后,注释掉此方法

  • 相关阅读:
    第十一周作业
    第十周作业
    第九周作业
    第八周作业
    第九周
    第八周
    第七周
    第六周
    第五周
    实验报告二
  • 原文地址:https://www.cnblogs.com/hellowzd/p/5484561.html
Copyright © 2011-2022 走看看