Why does my primary key jump large amounts when I use xmlhttprequest to capture data?

Viewed 159

EDIT This question is almost a duplicate of this question from 2010, except that I'm not using transactions, so none of the answers make sense.

EDIT I am not asking how to reset the primary key. I am asking why the primary key is not auto-incrementing by consecutive numbers.


I'm using xmlhttprequest to capture as-you-type information and store it in my Mysql database.

HTML

<input type="text" name="example" onKeyUp="saveData(this)">

JAVASCRIPT

function saveData(a){
    var z;
    var d=new FormData();
    d.append('data',a.value);
    if(window.XMLHttpRequest){z=new XMLHttpRequest();}else{z=new ActiveXObject("Microsoft.XMLHTTP");}
    z.onreadystatechange=function(){if(z.readyState==4&&z.status==200){if(z.responseText=='false'){alert(z.responseText);}}}
    z.open("POST", '/scripts/save_data.php');
    z.send(d);
}

PHP For testing purposes I'm hard-coding the uid user id.

<?php
$stmt=$pdo->prepare("INSERT INTO `user_data` (`uid`, `data`) VALUES (:myuid,:mydata) ON DUPLICATE KEY UPDATE `data`=values(`data`)");
$stmt->bindValue('myuid',1,PDO::PARAM_INT);
$stmt->bindParam('mydata',$_POST['data'],PDO::PARAM_STR);
$stmt->execute();

My MySQL table has...

id, primary INT(10) unsigned auto-increment
uid, INT(10) unsigned
data, VARCHAR(24)

Everything works as expected, but I'm not seeing the values of id increment sequentially as I would expect (1, 2, 3, etc.). It's jumping (1, 20, etc.) as if lines have been created, then dropped, to form the final line. Can anyone explain this behavior? Need I worry about it?

1 Answers
Related