$q = $db->prepare('INSERT IGNORE INTO Cities (Name,Stamp) VALUES (?,?)');
$q->execute(array($city,$stamp));
I am running this code to insert new cities in the Cities table. I just noticed that every query increments the id field, and that's not what I want. It's not like I rely on the id values being gapless, but it's ridiculous to increment every time the code is run.
So, what kind of smart SQL query can I run to give me the same functionality without doing two queries (first SELECT, then INSERT) and that does not auto_increment?
Table description:
Field Type Null Key Default Extra
id int(11) NO PRI NULL auto_increment
Name varchar(100) YES UNI NULL
countryid int(11) YES NULL
Stamp int(11) YES NULL
uid int(11) YES NULL
The code:
INSERT INTO Cities (Name,Stamp) VALUES (?,?) ON DUPLICATE KEY UPDATE Name = Name
increments the value on my table. The MySQL version is 5.5.9. The database engine is innoDB.
Possibly it can be this bug: http://bugs.mysql.com/bug.php?id=28781 If you scroll down to the bottom you can see that it's still an issue, three years later...