我有一个 csv 文件,其中 9 个缺少数据(csv 文件的大小为 229mb)。我将 csv 文件拆分为更小的,即一个 csv 包含 4000 或 5000 个数据。我上传 csv 文件并从中读取数据并将其插入数据库.1st我将数据插入到一个虚拟表中并列出它。然后提交列表并插入到主表中。但这需要超过1小时。我的代码是,
$path = "csv1.csv";
if (($handle = fopen("$path", "r")) !== FALSE) {
$cntcnt=1;
while (($info = fgetcsv($handle, 10000, ",")) !== FALSE) {
foreach($info as $key=>$value) {
$datas[$key]=$value;
if(isset($datas[3])) $bname = $datas[3]; else $bname = "";
if(isset($datas[4])) $address = $datas[4]; else $address = "";
if(isset($datas[5])) $city = $datas[5]; else $city = "";
if(isset($datas[7])) $zipcode = $datas[7]; else $zipcode = "";
if(isset($datas[8])) $cname = $datas[8]; else $cname = "";
if(isset($datas[13])) $phone = $datas[13]; else $phone = "";
if(isset($datas[14])) $fax = $datas[14]; else $fax = "";
if(isset($datas[15])) $email = $datas[15]; else $email = "";
if(isset($datas[16])) $website = $datas[16]; else $website = "";
$bname= mysql_real_escape_string($bname);
$cname= mysql_real_escape_string($cname);
$address =mysql_real_escape_string($address);
$city =mysql_real_escape_string($city);
$data=array('vendorid'=>$vendorid,'cid'=>$cid,'scid'=>$scid,'sscid'=>$sscid,'rid'=>$rid,'pid'=>$pid,'rcid'=>$cityid,'lid'=>$lid,'bname'=>$bname,'address'=>$address,'street'=>$street,'zipcode'=>$zipcode,'phone'=>$phone,'cell'=>$cell,'fax'=>$fax,'email'=>$email,'website'=>$website,'description'=>$description,'mapaddress'=>$mapaddress,'price'=>$price,'date'=>$date,'ref_code'=>$ref_code,'realestate_category'=>$realestate_category,'template'=>$template,'busname'=>$busname,'code'=>$code,'b_type'=>$b_type,'edit_date'=>$edit_date,'phone2'=>$phone2,'cname'=>$cname,'ssscid'=>$ssscid);
$this->db->insert('c_tbldummy',$data);
}
}
有什么办法可以加快这个过程吗?因为我的客户想上传50000到75000的数据。任何人请帮助我。