编程语言
首页 > 编程语言> > PHP 批量插入数据

PHP 批量插入数据

作者:互联网

foreach ($sheetContent as $k => $v){
    $arr['customerName'] = $v[0];
    $arr['sex'] = $v[1];
    $arr['typeId'] = $v[2];
    $arr['customerPhone'] = $v[3];
    $arr['sourceId'] = $v[4];
    $arr['birthday'] = $v[5];
    $arr['customerwechat'] = $v[6];
    $arr['customer_remarks'] = $v[7];
    $arr['createTime'] = time();
    $res[] = $arr;
};
 
$num = 100;//每次导入条数
$limit = ceil(count($res)/$num);
for($i=1;$i<=$limit;$i++){
    $offset=($i-1)*$num;
    $data=array_slice($res,$offset,$num);
    $result=Db::name('customer')->insertAll($data);
};

  

标签:typeId,arr,customerName,批量,res,sex,插入,num,PHP
来源: https://blog.51cto.com/u_13481146/2819266