Mysqli multiple row insert, simple multi insert query

后端 未结 2 661
傲寒
傲寒 2020-12-02 00:25

How do I insert this query with mysqli?...

INSERT INTO table (field1, field2, field3) VALUES (\'value\', \'value\', \'value\'), (\'value\', \'value\', \'valu         


        
2条回答
  •  执笔经年
    2020-12-02 01:00

    Mysqli is not a database of it's own, but just a set of functions to send your query in old mysql.

    So, using mysqli you can run any mysql query.

    However, in case of dynamically supplied values you cannot avoid "extra funky stuff in PHP" as you are supposed to use prepared statements for that. And, unfortunately, raw mysqli is not that easy with them.

    So, to perform such insert you will need to create a query with placeholders first

    INSERT INTO table (field1,field2,field3) VALUES (?, ?, ?), (?, ?, ?), (?, ?, ?);

    then bind all the values using call_user_func_array()
    and finally execute;

提交回复
热议问题