php - How to stop row ID from getting bigger -


i have code, parses json , beeing run every 5 mins via php file.php command.

foreach($data->chatters->staff $viewers) {     $sql = "insert viewers (user,points)             values('$viewers','10')             on duplicate key update              points = points+5";      if ($conn->query($sql) === true) {     //echo "staff: done"; } else {     echo "error: " . $sql . "<br>" . $conn->error; } } 

for reason, every cycle increases id count. database looks this:

id user points 1 uname1 123 2 uname2 123 18 uname3 123 256 uname4 123 

and id value keeps increasing. missing?

thanks.

before explaining: experiencing normal.

the id number gets generated every insert query. it's atomic operation, plus feature designed work in concurrent environment (many people hitting 1 db lots of requests).

in order able concurrently serve, mysql isolates transactions each other , each transaction lives own "bubble". means, every time insert happens , auto_increment generated, can't produce same value different queries.

the way work mysql increase number , never re-use it. that's possible solution , fastest 1 well.

what mean - means every time hit unique constraint in query, value generated auto_increment "wasted", insert won't happen , instead update part gets executed.

you can't fix it, can break it. leave is, you've done right.

the job of auto_increment provide unique numbers. if got spent somehow (by failed insert) that's fine , not need worry about.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -