您的位置:首页 > 编程语言 > PHP开发

thinkphp扩展 根据前端批量建立字段

2016-05-12 09:59 706 查看
/*批量添加字段辅助*/
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'); 批量建立完字段后,注释掉此方法

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: