0

I have used $mysqli->insert_id;which returned a single ID. How can I retrieve IDs for multiple inserted rows in mysqli. Is there a solution?

Aaron
  • 1
  • 1

3 Answers3

1

Use the following query:

SELECT * FROM myTable WHERE myColumn IN ($ids);

Please refer to this answer and its thread for more info on the subject.

EDIT: Misinterpreted the question. @DevLakshman has got the right idea.

Community
  • 1
  • 1
D. Visser
  • 875
  • 2
  • 12
  • 19
  • Based on the inclusion of `$mysqli->insert_id;` I think @Aaron is trying to get the IDs of the records as they are inserted into the database, not return the records based on know IDs – foxbeefly May 25 '15 at 09:01
  • I just reread the question and I'm afraid I misinterpreted it. I will edit my answer. – D. Visser May 25 '15 at 09:02
0

Your next ids will be the succession of generated $mysqli->insert_id + the next n (number of inserts rows) as your statement is doing it in one transaction.

Afsar
  • 3,104
  • 2
  • 25
  • 35
0

If you are executing your insert query in loop then get the ids by $mysqli->insert_id; by writing it in loop or if manually writing many queries then write $mysqli->insert_id; correspondingly...

lakshman
  • 656
  • 4
  • 18