balkrishna Posted October 17, 2013 Share Posted October 17, 2013 Hey, I would like to import data from CSV files to my application, First i've upload csv on to server then get csv contents by fgetcsv(), after that i want to map uploaded data and validate then send to db otherwise show error. Please suggest me how to do. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/283045-importing-data-mapping-from-csv-files/ Share on other sites More sharing options...
Barand Posted October 17, 2013 Share Posted October 17, 2013 Have you looked at MySQL's "LOAD DATA INFILE" statement http://dev.mysql.com/doc/refman/5.6/en/load-data.html Quote Link to comment https://forums.phpfreaks.com/topic/283045-importing-data-mapping-from-csv-files/#findComment-1454243 Share on other sites More sharing options...
vinny42 Posted October 17, 2013 Share Posted October 17, 2013 Indeed. Use your database for what it's good at; create a table that has the exact columns of the CSV and use LOAD DATA INFILE to fill it with the CSV data. Then use separate queries to copy the data from that table to your actual database. This way you can check if the CSV has loaded correctly without having to parse the data, and you can easily manipulate the data where needed. (like remove duplicates, find empty fields, etc) The reasing behind this method is that you can use one query to check/change all records. If the data in the new table passes a handfull of sanitycheck queries, you're good to import it for real. Quote Link to comment https://forums.phpfreaks.com/topic/283045-importing-data-mapping-from-csv-files/#findComment-1454255 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.