Writing a PHP file to read from CSV and execute SQL Query

前端 未结 6 1739
深忆病人
深忆病人 2020-12-30 12:39

I would like a PHP script to read the contents from a CSV file in the following format

id, sku
1,104101
2,105213

there are a total of 1486

6条回答
  •  离开以前
    2020-12-30 12:39

    fgetcsv can be used to parse CSV files. mysql_query method could be used to perform MySQL queries.

    The complete code is as follows:

    \n";
    while (($data=fgetcsv($fin,1000,","))!==FALSE) {
        $query = "UPDATE catalog_product_entity SET sku='$data[1]' WHERE entity_id='$data[0]'";
        mysql_query($query);
        echo "Record updated 
    \n"; } fclose($fin); mysql_close(); ?>

提交回复
热议问题