4,250
社区成员
发帖
与我相关
我的任务
分享 for ($i=0;$i<count($listarray2);$i++) { //$listarray2有1700多条数据
$explist = explode("\t",$listarray2[$i]); //以空格分隔,填入$explist数组。
$sql ="insert into stock_trade_list (StockID,StockName,upRange,currentPrice,totalHand,areHand,leftClose,opening,highest,minimun,callToBuy,peddle,speedUp,compareNumber,earnings,cityNet,volumeBuying,volumesold,commissioned,amplitude,changingHands,changeRange,amount,amountOfbothT,numberof,handPerT,outside,within,totalMarketValue,flowOfValue,contribute,insertTime) values ('".$explist[0]."','".$explist[1]."','".$explist[3]."','".$explist[4]."','".$explist[5]."','".$explist[6]."','".$explist[7]."','".$explist[8]."','".$explist[9]."','".$explist[10]."','".$explist[11]."','".$explist[12]."','".$explist[13]."','".$explist[14]."','".$explist[15]."','".$explist[16]."','".$explist[17]."','".$explist[18]."','".$explist[19]."','".$explist[20]."','".$explist[21]."','".$explist[22]."','".$explist[23]."','".$explist[24]."','".$explist[25]."','".$explist[26]."','".$explist[27]."','".$explist[28]."','".$explist[29]."','".$explist[30]."','".$explist[31]."',now());";
mysql_query($sql) or die("Query failed :" . mysql_error());
}
$filename = microtime(true).'.sql';
if (false !== ($handle = fopen($filename, 'x'))) {
foreach ($listarray2 as $row) {
$explist = explode("\t",$row);
unset($explist[2]);
$sql ="insert into stock_trade_list (StockID,StockName,upRange,currentPrice,totalHand,areHand,leftClose,opening,highest,minimun,callToBuy,peddle,speedUp,compareNumber,earnings,cityNet,volumeBuying,volumesold,commissioned,amplitude,changingHands,changeRange,amount,amountOfbothT,numberof,handPerT,outside,within,totalMarketValue,flowOfValue,contribute,insertTime) values ('".implode("','",$explist)."',now());";
fwrite($handle, $sql.PHP_EOL);
}
fclose($handle);
$sql = 'LOAD DATA INFILE "'.realpath($filename).'" INTO TABLE stock_trade_list';
mysql_query($sql) or die("Query failed :" . mysql_error());
unlink($filename);
} else {
echo "The file $filename is not writable or cannot open.";
}