I have a query which runs on each page load on my website. In a simple form, it checks if the users IP is in the database and if it isn't it will add it, and do nothing if it is. To save myself having to run two queries to accomplish this (one to check and one to insert) I'm using this SQL:
INSERT IGNORE INTO `limits`
SET `ip` = :ip, `limit` = :limit
This is meant to do nothing if :ip
already exists and create the record if it doesn't. It works fine, however I am noticing that my primary key for the table is incrementing on every page load.
For example, the primary key field is called id
and it's int(11) AUTO_INCREMENT
. The first record in the database obviously had an id
value of 1
. After refreshing the page 10 times, it now has a value of 11
, even though my IP hasn't changed and the query doesn't insert a new record.
Is there any way of making the query not update the id
field on every execution?