Reputation: 25
I am a bit of a newbie to php but I am wondering the best way to achieve this and would be glad of any tips.
I want a php page where I can import a CSV or paste into a multiline box, then push a button which checks each imported line against a mysql database "blacklist" and removes any records that exist in the database, and then exports / displays the list without the blacklisted records that existed in the database.
Should I import the entire CSV to a temp table then do the removal using SQL queries... i.e delete from temptable where id in blacklisttable, then export temp to csv?
This may slow it down if the file has to be inserted to sql. Is there a better way?
Upvotes: 0
Views: 85
Reputation:
If you set this up properly you can do the whole operation in a few lines of PHP and just two SQL commands. Your question is short on detail, so this is necessarily going to be a little sketchy:
Upload file to server with PHP.
Use SQL 'LOAD DATA INFILE' to load the CSV file into a table.
Use 'SELECT... INTO OUTFILE...' to export the data to a CSV file, filtering with a suitable WHERE clause.
Download the resulting CSV file with PHP, or by providing a link, or whatever
I am assuming that you trust the data you're uploading. If not, you may need to do some validation as part of the LOAD DATA INFILE... process, or by some other method.
Inserting data with LOAD DATA INFILE
and using SQL to handle the filtering will be orders of magnitude faster that doing record-by-record look-ups with PHP.
Upvotes: 1