Reputation: 11
i have a .csv file with rows like this:
16.11.2015 00:00:01.118,0.94674,0.94641,1000000.0000,1750000.0000
now i'd need to import the values to mysql database to a table with 9 cols so:
col1 - 16.11.2015 col2 - 00 col3 - 00 col4 - 01 col5 - 118 col6 - 0.94674 col7 - 0.94641 col8 - 1000000.0000 col9 - 1750000.0000
has anyone an idea how to separate the values f.e. with standard command like : load data infile 'file.csv' into table nameoftable fields terminated by ',';
i tried to look for something on mysql knowledge base but no resuld, which would be work...thanks
Upvotes: 0
Views: 431
Reputation: 166
Have you looked at http://dev.mysql.com/doc/refman/5.7/en/load-data.html?
Also, some database manager/tools have the ability to import CSV files. I'm using Sequel Pro and it has the ability to do so.
Upvotes: 0
Reputation: 11
i'd like to a direct mysql command if it is possible? i'd like to load the csv file directly to the DB with LOAD command.
Upvotes: 0
Reputation: 3
Are you looking for something like this?
$file_handle = fopen($file, "r"); //opens CSV
while (($row = fgetcsv($file_handle, 1000, ",")) !== false){
...code..
}
http://php.net/manual/fr/function.fgetcsv.php
Upvotes: 0