CSV read ve MySQL insert çalışma örneği sunabilen herkes - hepsi utf8 ile? Bunu nasıl yapacağını anlayamıyorum (uzun saatler ...). MySQL harmanlama tüm utf8mb4_unicode_ci (veritabanı, tablo, sütun).PHP CSV MySQL insert (utf8)
Yardımlarınız için teşekkürler!
<?php
header('Content-Type: text/html; charset=UTF-8');
mysql_connect("localhost","root","");
mysql_query("SET NAMES utf8");
mysql_select_db("test");
if (!empty($_FILES['csv']['size']) && $_FILES['csv']['size'] > 0){
$file = $_FILES['csv']['tmp_name'];
utf8_encode(fgets($file));
$handle = fopen($file,"r");
do {
if ($data){
$data = array_map("utf8_encode", $data);
mysql_query("INSERT INTO mytable (id,text) VALUES
(
'".addslashes($data[0])."','".addslashes($data[1])."'
)");
}
}
while ($data = fgetcsv($handle,1000,",","'"));
header('Location: index.php'); die;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="index.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input name="csv" type="file" id="csv" accept-charset="utf-8"/>
<button type=submit>UPLOAD</button>
</form>
</body>
</html>