I have been experimenting with LOAD DATA INFILE and there are a couple things I would like to be able to do. I’m not sure if they are possible, or if I may need to create a temporary table for the upload.
When a CSV file is uploaded/inputed in my application, I’d like to have an auto-incrementing column for the rows. In addition, I’d like to add a column value to each row identifying the user who uploaded the file.
I am using PHP/MySQLi on a InnoDB database.
I may also have empty strings for null values in my CSV files. Is there a simple way to input these values as NULL into the database?
Thanks for all your help!
to achieve what you want, you would need to programmatically pre-create the table first along with a triggers function prior to loading data into it.
therefore, create the table first with triggers:
example:
to test if the trigger works:
you can now load the data to the specific column.
example: