insert multiple rows via a php array into mysql

后端 未结 12 1514
自闭症患者
自闭症患者 2020-11-21 22:35

I\'m passing a large dataset into a MySQL table via PHP using insert commands and I\'m wondering if its possible to insert approximately 1000 rows at a time via a query othe

12条回答
  •  无人共我
    2020-11-21 23:22

    I know this is an old query, but I was just reading and thought I'd add what I found elsewhere:

    mysqli in PHP 5 is an ojbect with some good functions that will allow you to speed up the insertion time for the answer above:

    $mysqli->autocommit(FALSE);
    $mysqli->multi_query($sqlCombined);
    $mysqli->autocommit(TRUE);
    

    Turning off autocommit when inserting many rows greatly speeds up insertion, so turn it off, then execute as mentioned above, or just make a string (sqlCombined) which is many insert statements separated by semi-colons and multi-query will handle them fine.

    Hope this helps someone save time (searching and inserting!)

    R

提交回复
热议问题