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'); 批量建立完字段后,注释掉此方法
相关文章推荐
- 在php中定义常量时,const与define的区别
- Eidtplus常用快捷键
- 读取()txt文件中的内容与向txt文件中写入内容(覆盖重写与在末尾续写+FileOutputStream与FileWriter)
- 每天laravel-20160805| Container -8
- 每天laravel-20160805| Container -8
- phpcms头部代码详细分析
- Yii2 return redirect()
- phpcms v9 修改文件时空白
- yii2带搜索功能的下拉框实例详解
- 黄聪:PHP解决textarea内容换行存入数据库,如何解析取出不能自动换行
- PHP简单工厂设计模式,简单代码。(缺点请指正,互相学习)
- PHP学习心路历程
- PHP中抽象类与接口的区别
- php通过iframe实现局部刷新
- Thinkphp 生成的验证码不显示问题解决
- yii2带搜索功能的下拉框实例详解
- php ucwords() 函数将字符串中每个单词的首字符转换为大写(实现代码)
- php使用文本统计访问量的方法
- PHP 的比较运算与逻辑运算详解
- php反射类ReflectionClass用法分析