tags:

views:

13

answers:

1

I noticed during testing the the database will jump a number in the index if someone else inserts a record while I've issued the nextId(). Does issuing this command reserve the next id?

Example:

User 1:

$nextId = $db->nextId('id');
echo "Next id: ".$nextId."<br />";

results: 1234, but no insert happen as I'm just getting the nextId()

User 2: (Just right after user 1)

$rs = $db->query(INSERT NEW RECORD HERE...);

id = 1235, Inserted new record

Now I go to query the DB manually and I see record id 1233 and 1235, but the 1234 that I did the nextId() for is missing in the DB.

Is this the expected results?

+1  A: 

Is this the expected results?

Yes. This is the expected behavior.

The reason for this is that it allows you to use that id without fear that other inserts performed by outside clients may be assigned that id, preventing you from using it.

From the manual:

Returns the next available number from a sequence. The sequence is automatically incremented each time this method is called.

webbiedave
so by reserving the id I can expect that it will be skipped if another user enters in a new record. Awesome!!!
Phill Pafford