CSVをループして、いくつかのレコードの名前フィールドをテーブルに挿入/更新しています。スクリプトは、レコードを挿入することを意味し、レコードが存在する場合は、名前フィールドのみを更新します。
より大きなCSVファイルにはかなりの時間がかかるため、このコードを、レコードの名前フィールドのみを更新するON DUPLICATEKEYUPDATEコマンドを使用して複数のINSERTクエリに変更できるかどうか疑問に思いました。
CSVには、テーブルのすべてのフィールドが含まれているわけではなく、主キーと名前のフィールドのみが含まれています。そのため、この場合、REPLACEは機能しません。
if (($handle = fopen($_FILES['csv']['tmp_name'], "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$title = 'Import: '.date('d-m-Y').' '.$row;
# CHECK IF ALREADY EXISTS
$explode = explode('-',$data[0]);
$areacode = $explode[0];
$exchange = $explode[1];
$number = $explode[2];
$update = "INSERT INTO ".TBLPREFIX."numbers SET
area_code = ".$areacode.",
exchange = ".$exchange.",
number = ".$number.",
status = 1,
name = '".escape($data[1])."'
ON DUPLICATE KEY UPDATE name = '".escape($data[1])."'";
mysql_query($update) or die(mysql_error());
$row++;
}
fclose($handle);
$content .= success($row.' numbers have been imported.');
}