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'); 批量建立完字段后,注释掉此方法

 

posted @ 2016-05-12 09:59  fleam  阅读(289)  评论(0编辑  收藏  举报