I need a PHP script which will update existing MySQL table getting data from a CSV. Table field hasweb need to be updated comparing a field consultant_id.
So MySql query should be
UPDATE user_data
SET hasweb="something"
WHERE consultant_id = "something";
Please help me to write a PHP script which can execute this query as many times as needed, depending upon CSV data.
I have written little php scripts to accomplish this many times and there are many ways go to about it:
The best according to my experience is to use CSV functions provided by PHP, take a look at fgetcsv(), because manually opening file and reading it line by line and parsing can cause complications.
Now you just loop through all the rows in csv and prepare query dynamically and execute it, for example (assuming that column 0 has IDs and column 1 has “hasweb”)
Hope that helps. If still stuck, Please ask me 🙂