PHP - Import CSV file to mysql database Using LOAD DATA INFILE

后端 未结 2 728
轻奢々
轻奢々 2020-11-28 08:16

I have a .csv file data like that

Date,Name,Call Type,Number,Duration,Address,PostalCode,City,State,Country,Latitude,Longitude
\"Sep-18-2013 01:53:45 PM\",\"         


        
2条回答
  •  一向
    一向 (楼主)
    2020-11-28 09:02

    Insert bulk more than 7000000 record in 1 minutes in database(superfast query with calculation)

        mysqli_query($cons, '
        LOAD DATA LOCAL INFILE "'.$file.'"
        INTO TABLE tablename
        FIELDS TERMINATED by \',\'
        LINES TERMINATED BY \'\n\'
        IGNORE 1 LINES
        (isbn10,isbn13,price,discount,free_stock,report,report_date)
         SET RRP = IF(discount = 0.00,price-price * 45/100,IF(discount = 0.01,price,IF(discount != 0.00,price-price * discount/100,@RRP))),
             RRP_nl = RRP * 1.44 + 8,
             RRP_bl = RRP * 1.44 + 8,
             ID = NULL
        ')or die(mysqli_error());
        $affected = (int) (mysqli_affected_rows($cons))-1; 
        $log->lwrite('Inventory.CSV to database:'. $affected.' record inserted successfully.');
    

    RRP and RRP_nl and RRP_bl is not in csv but we are calculated that and after insert that.

提交回复
热议问题