How to do multiple simultaneous inserts with php

Asked

Viewed 1,510 times

2

I need to go through a json and take the values and insert into the bank but I think it would be a bad idea to put an Insert inside a loop.

I would like to know how to do several simultaneous php Inserts.

1 answer

4


Concatene the Inserts with ; or do INSERT as follows:

INSERT INTO tabela(coluna1, coluna2, coluna3)
VALUES
     (valor1, valor2, valor3),
     (valor4, valor5, valor6),
     (valor7, valor8, valor9) ...
  • 1

    Exactly this answer Silvio Andorinha! :-)

  • What I recommend is to do the Insert in multiple lines as @rodrigorigotti commented for the reason that the database processing is much faster.

  • Example of the mysql manual: INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.