1

MySQL code is something like:

INSERT INTO table(name, value) VALUES ('name1', 'value1'), ('name2', 'value2'), ('name3', 'value3')

Basically, multiple inserts in the same SQL statement.

How can I get the IDs of the inserted values. I assume mysql_insert_id() combined with the number of inserts isn't safe since someone else might insert something at the same time.

Is there another way?

cgf
  • 3,369
  • 7
  • 45
  • 65

1 Answers1

2

You either need to insert them one at a time or figure out the id's with a followup query.

INSERT INTO table(primkey, value) VALUES ('pk1', 'val1'), ('pk2', 'val2');
SELECT FROM table id, primkey where primkey in ('pk1', 'pk2');
NovaDenizen
  • 5,089
  • 14
  • 28