I have a CSV file of products which need to be added or updated if exists and leave the old ones even if it has been removed from the list.
I have a loop like this:
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
Which works just fine, from it I assign few variables like this:
$price = htmlspecialchars(mysql_real_escape_string($data[2]), ENT_QUOTES, 'utf-8' );
After I have set 4 variables I need, I query MySQL like this:
mysql_query("SELECT * FROM products WHERE productid = '$prodid' AND supplier = 'SUPPLIER1'")
If it results 1 or more we just update it
mysql_query("UPDATE tuotteet SET
supplier = 'SUPPLIER1',
product = '$product',
prodid = '$prodid',
ean = '$ean',
price = '$price' WHERE prodid= '$prodid' AND supplier = 'SUPPLIER1'") or die(mysql_error());
If product not found from database, we make another query INSERT. Problem is that this is a very slow way to do this, it takes many many minutes to go through about 10000 productlines.
Anything to do with this?