我想我需要第二双眼睛看这个。对于我的一生,我无法弄清楚为什么我的 SQL INSERT 查询每次迭代都会运行两次:
if (($handle = fopen($spreadsheet_url, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if ($current_row == 1 || $current_row == 2) {
$num = count($data);
//echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
//echo $data[$c] . "<br />\n";
try {
set_time_limit(0);
$stmt = $db_temp_kalio->prepare('INSERT INTO invupdate (sku,prod) VALUES(:sku, :prod)');
$stmt->execute(array(':sku'=> $data[0], ':prod'=> $data[1])); }
catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
exit; }
}
}
$current_row++;
}
fclose($handle);
}