I\'ve already looked at other answers and I still feel that my question is relevant and deserves a separate entry.
I have a table named settings(which stores user se
This behaviour shouldn't be relied upon; besides the obvious locking issues, let's say you want to set up master<->master replication; all of a sudden, the id's increment by 2 every time.
Besides that, instead of actually writing multiple insert statements, it might be worth using prepared statements:
$db = new PDO(...);
$db->beginTransaction();
$stmt = $db->prepare('INSERT INTO `mytable` (a, b) VALUES (?, ?)');
foreach ($entries as $entry) {
$stmt->execute(array($entry['a'], $entry['b']));
$id = $db->lastInsertId();
}
$db->commit();