skip to Main Content

I’m quite a new php programmer and cannot seem to figure out where I’m going wrong with inserting records into my MySQL database:

My test script (for learning purpose) calls the eBay API and downloads the requested information into the MySQL database but I seem to be getting the issue of the script skipping IDs on the Auto Increment. From what I have been reading here this is normally when records have been deleted but this is not the case for me as none have been deleted and the gaps get bigger and bigger.

My question is: Is there something else that can cause the id to skip random numbers?

Database example:
Number run from 1-21 just fine but then goes: 28,43,51,55,58
I have checked and next to be added should be 59:

show create table 'tbl'

2

Answers


  1. Is your code using transactions? If you rollback a transaction that inserts into that table it doesn’t roll back the identity counter even if the transaction gets rolled back.

    See this question: MySQL table with AUTO_INCREMENT primary id does not release the number after a rollback.

    Login or Signup to reply.
  2. I am kind of guessing what the code will look like, since I am too working with PayPal APIs now, but here is a way to let the auto_increment do it’s job

    This is how my INSERT command looks like and its been always working. But providing some code will definitely help.

    "INSERT INTO `table` (auto_increment_id, field1, field2, field3) VALUES ('','$field1','$field2','$field3')";
    

    If you leave the first () blank and just put values after VALUES you
    have to go with every field, but in the way I showed you, you say
    which field should get what value.

    To connect to live database you can use SQLite. They are called database browsers.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search