Problem:
insert on duplicate key update
inserts two rows into table from PHP only and Xampp/Windows only
Test code:
$connection = new \PDO('mysql:dbname=XXXXXXXXX;host=XXXXXXXX', 'XXXXXXXX', 'XXXXXXXX');
$query = 'insert into `test` (test) VALUES (1) on duplicate key update test=1';
$connection->exec($query);
Mysql schema:
CREATE TABLE IF NOT EXISTS `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`test` varchar(200) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
Server:
xampp-win32-7.0.18-0-VC14
Additional information:
- Tested on multiple MySQL servers, from the same web server
- When testing on a Linux server, also with PHP7, the problem was fixed
- So the problem seems to be with the php mysql extension
- I'm still diagnosing but hoping this issue can be resolved for documentation
EDIT:
As mentioned below, it seems this question is easily mis-interpretted. I am aware that a key is required for the condition to insert/update against one row. This is not the intent and it is not the question. Given the case that a key is not used, the IODKU statement should insert a row every time it is run. It is inserting 2 rows after running 1 time