开发者

PDO Get Multiple Insert Ids

Running the following query using PDO (Actually, I use prepared statements but same problem)

INSERT INTO MyTable(MyFie开发者_运维知识库ld) VALUES('Row1'), ('Row2')

How can I get the Ids for the records relating to Row1 and Row2?

$db->lastInsertId() literally returns the last single Id.

Is it sufficient to take this last Id, subtract the # of records and assume that range covers all my records? can there be gaps/jumps. Is this query guaranteed to be atomic?


If you're using MyISAM tables then because of the table level locking mechanism it's only possible for you to get given a range of ids.

After reading http://dev.mysql.com/doc/refman/5.5/en/innodb-auto-increment-handling.html#innodb-auto-increment-traditional assuming you're using "traditional" innodb locking (which likely you are) then again for a single statement the set of IDs will be sequential.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜