I am looking for a generic php script that will let me select a csv file (see sample below) and insert the data in the file in to a mysql database. Details of the the upload should be displayed on the screen. In case of errors, the exact error and line number should also be mentioned. The following features are required.
1) The database name, server ip, username and password would be configured in the script.
2) The table name would be the first row of the csv file.
3) The column names would be the second row of the csv file.
4) The delimiter used in the CSV would be comma (,) but it should be configurable at the top of the script in case I need to change it. All data elements would be enclosed in double quotes ("). Commas in between two double quotes should be ignored.
5) MySQLi should be used.
6) mysqli_real_escape_string() Function should be used to escape any special character.
7) After completing the execution of the script, the number of records inserted should be displayed.
8) In case of error, the entire file should be rolled back using mysql transactions. The line number and error details of the first encountered error should be displayed.
9) Basic validation of the csv file should be done. The following errors should be captured.
-a The database and table name should be a valid one.
-b Column names in the file should be found in the table.
-c Right number of data elements based on the first row
-d Proper enclosure of data in double quotes.
-e NULL values being inserted into NON-NULL columns.
-f proper handling of string and numeric values.
10) The script should be able to handle up to 10,000 rows.
SAMPLE CSV FILE
37 freelancers are bidding on average $154 for this job
Hi! I can help you with this project. Had a similar experience about uploading CSV and importing to MySQL. Do you need any special UI? Ready to discuss in chat
Greeting, I have understood your generic php script task and can do it with your 100% satisfaction. Please ping me for more discussion. I have more than 5 years of experience in MySQL, PHP