1. 하나씩 넣는 방법
<?php
include 'db.php';
$arr = [];
$file = fopen($_FILES['csv']['tmp_name'], 'r');
while( ($line = fgetcsv($file)) !== FALSE ) {
//array_push($arr, $line);
$name = $line[0];
$name = iconv("euc-kr", "utf-8", $name);
$sql = "INSERT INTO member(name, email) VALUES('". $name . "','" . $line[1]. "');";
//echo $sql;
$conn->exec($sql);
}
fclose($file);
$conn = null;
?>
2. 한방에 인서트 방법(2만줄)
<?php
include 'db.php';
$arr = [];
$file = fopen($_FILES['csv']['tmp_name'], 'r');
$conn->beginTransaction();
while( ($line = fgetcsv($file)) !== FALSE ) {
//array_push($arr, $line);
$name = $line[0];
$name = iconv("euc-kr", "utf-8", $name);
$sql = "INSERT INTO member(name, email) VALUES('". $name . "','" . $line[1]. "');";
//echo $sql;
$conn->exec($sql);
}
$conn->commit();
fclose($file);
$conn = null;
?>