Batch inserts with PHP

前端 未结 2 333
野趣味
野趣味 2021-01-23 21:21

Java has the PreparedStatement addBatch + executeBatch to do multiple insertions efficiently.

What is the fasted way to do a batch of inserts using php\'s mysqli extensi

相关标签:
2条回答
  • 2021-01-23 21:51

    MySQL natively supports multiple insertions with one query.

    INSERT INTO [Table] ([Column List])
    VALUES ([Value List 1])
         , ([Value List 2])
           [...]
         , ([Value List N])
    
    0 讨论(0)
  • 2021-01-23 22:09

    I realize this question is old, but for anyone else that comes across this, I found some useful information on this topic here: insert multiple rows via a php array into mysql.

    Depending on your needs, it may be fastest to pipe the data as csv directly into LOAD DATA INFILE. However, be very cautious with this approach as it offers no protection against injection attacks.

    I have used this approach in the past, validating the data cleanliness during csv generation.

    0 讨论(0)
提交回复
热议问题