<?php
header("content-type:text/html;charset=utf-8");
//设置代码执行不受时间限制
set_time_limit(0);
//链接数据库
$con = mysqli_connect("127.0.0.1","root",‘‘,‘test‘);
if(mysqli_connect_error()){
die("链接错误:".mysqli_connect_error());
}
//设置编码为utf-8
mysqli_set_charset($con,"utf8");
//需要插入的数据
$str = ‘julia[email protected],11023628162
[email protected],11008346280‘;
//根据tab换行符切换为数组
$str = explode("\t", $str);
$data = array();
$i = 0;
foreach($str as $v){
//用逗号分割为数组
$data[] = explode(",",$str);
}
$value = ‘‘;
//设置插入数量
$query_num = 2;//可以设置为10万
for($i=1;$i<$query_num;$i++){
//去掉源数据空格
$a = trim($data[$i][0]);
$b = trim($data[$i][1]);
//拼接sql之value
$value .= "(‘$a‘,‘$b‘),";
}
//去掉字符串$value 最后一个逗号
$value = rtrim($value,",");
//拼接完整sql语句
$sql = "INSERT INTO `test`(`email`,`number`)values".$value;
//执行sql
$b = mysqli_query($con,$sql);
var_dump($b);