插入多条记录不要采取构建多条insert语句的写法,而是采取,一个insert语句,多组值的写法,这样会大大的调高效率.
以 insert into tb_user (id,user_name,pwd) values ("","zhangsan","12345");为例
插入十条重复的记录,insert十次的效率要比
insert into tb_user (id,user_name,pwd) values ("","zhangsan","12345"),("","zhangsan","12345"),("","zhangsan","12345"),("","zhangsan","12345"),("","zhangsan","12345"),("","zhangsan","12345"),("","zhangsan","12345")的效率滴很多
笔者插入14个字段,insert在navicat要30.几s.
而采用上述一句的写法,只需要1.207秒
$sql = 'insert into score_copy (id,xh,bj,ksh,class,name,chinese,math,english,wuli,huaxue,shengwu,history,dili,zhengzhi) values ';foreach ($data as $arr) {$sql.='(""';foreach ($this->map as $k => $v) {echo $this->cellValue($arr, $k) . '
';
$sql .= ',"' . $this->cellValue($arr, $k) . '"';
}$sql.='),';//echo $sql;
}
re