at first lastInsertId() return the last insertd id and not the first, so $lastID = $firstID + $count - 1; is wrong
secondly concurrent batch insert (2 different user that call the same page that does the batch insert at same time) do not produce sequential id
batchinsert can’t return id by design since the format of the generated sql is (with some difference based on db)
INSERT INTO user ('name', 'age') values ('Tom', 30), ('Jane', 20) ,('Linda', 25);
So it is not possible to return the ids.
If you need the id create your own batch procedure that does single insert.
batchInsert is much faster but if you need REAL id is the only way (not completely true, by doing some change on the table and a couple lines of code you can still get them)
The application design depends also on usecase.
Even if batchInsert is the optimum on developer side, in some case can be insignificant on user side
10000 record as single insert will take 3 sec of execution
- 3 second 2 time per day is an acceptable time for the user.
- 3 seconds every 5 minute is still ok but maybe become annoying.
- 3 second every minute of work probably start to be unacceptale
So mostly depends on how many time you need to run this batch insert and how (user or cronjob) and on how many data (=execution time).