excel复制粘贴两列批量插入到sql中
需求和简单,excel中两列数据,要一次插入到sql表中
当然,
列要一样多
哦。而且最重要的,一定要trim
一下。
<?php$a='导入ID导入来源用户id微博ID微博昵称微博粉丝数微博关注数微博数微博描述微博认证原因新浪微博地址微博头像微博注册时间电话邮箱QQ号微信号姓名性别年龄生日星座民族省份城市地区人生阶段婚姻状态生育状态语言教育学校公司职业行业收入用户类型备注';$b='task_idsourceididstrscreen_namefollowers_countfriends_countstatuses_countdescriptionverified_reasonprofile_urlprofile_image_urlcreated_atphoneemailqqweixinnamegenderAgebirthdayhoroscopenationprovincecitylocationLife_stageMarital statusGrowth stateLanguageeducationschoolcompanyoccupationindustryincomeuser_typenote';$field_name=explode("\n",$a);foreach ($field_name as $key => &$value) { $value=trim($value);}unset($value);$culumn_name=explode("\n",$b);foreach ($culumn_name as $key => &$value) { $value=trim($value);}unset($value);foreach ($field_name as $key => $value) { $data[] = "('$field_name[$key]','$culumn_name[$key]')"; } echo $bb="insert into user_field (field_name,column_name) values ".implode(',',$data);