Answer the question
In order to leave comments, you need to log in
How to export data from csv to MySQL?
Good day. There is a csv file with a database dump, it has about 100,000 lines, and 14 columns with data (I only need 7 of them).
At first I tried to export like this:
<?php
include '../../connect.php';
LOAD DATA INFILE 'in.csv' INTO TABLE table FIELDS TERMINATED BY ';' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 ROWS;
?>
$csv_open = fopen("in.csv", "r");
$r = 0;
while (($row = fgetcsv($csv_open, 1000, ';', '"')) != FALSE)
{
$r++;
if($r == 1) {continue;} // Не дает записать в БД первую строку
$ins="INSERT INTO `table` (`id`, `street`, `house_number`, `app_number`, `description`, `device_id`, `old_meterage`) VALUES ('$row[0]', '$row[1]', '$row[2]', '$row[3]', '$row[8]', '$row[10]', '$row[13]')";
mysql_query($ins);
echo mysql_errno() . ": " . mysql_error();
}
fclose($csv_open);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question