I'm using pdo to handle my database and I've just noticed that when I try to insert multiple rows if I use ON DUPLICATE KEY UPDATE there is a gap in the auto-incremented field(in my case it is called id).
This is my table:
id | name | age
1 | Emma | 20
2 | Jane | 21
3 | John | 25
And my statement is:
$pdo->prepare('
INSERT INTO person
(`name`, `age`)
VALUES
(?, ?), (?, ?), (?, ?)
ON DUPLICATE KEY UPDATE
age = VALUES(`age`)
')->execute(['Emma', '20', 'Jane', '21', 'Sarah', '35']);
If i run this query it will insert name: Sarah, age: 35 with id 6(a gap of 2 ids). Why is this happening? And is there a solution to that?
(p.s i want it to work with multiple rows insert)