Why does the ON DUPLICATE KEY UPDATE statement increment by 2 instead of 1?

Which will cause the ON DUPLICATE KEY UPDATE statement to increase the value by 2 instead of 1, SQL im is used here:

INSERT INTO banner_view (banner_id,date,views) 
VALUES ('10',CURDATE(),'1')
ON DUPLICATE KEY UPDATE views=(views+1)

Here is the database schema:

CREATE TABLE `banner_view` (
`banner_id`  int(11) UNSIGNED NOT NULL ,
`date`  date NOT NULL ,
`views`  int(10) UNSIGNED NOT NULL ,
PRIMARY KEY (`banner_id`, `date`),
FOREIGN KEY (`banner_id`) REFERENCES `banner` (`banner_id`) ON DELETE CASCADE ON UPDATE CASCADE,
UNIQUE INDEX `banner_id` USING BTREE (`banner_id`, `date`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
ROW_FORMAT=COMPACT
;

I checked the MySQL log to ensure that the query is called exactly 3 times, but the output will be 6, what could be wrong?

UPDATE: this method is called inside the smarty template, for example: {App_banner :: getRandomBanner ()}

+3
source share
5 answers

The silver light is correct, you call the code twice. If you do not do this explicitly in code, that is:

inc3x();
inc3x();

Then perhaps you are loading the page twice. This can happen if you include an empty src document in the document. Example:

<script src=""></script>

.

+1

, - .

+2

, , , . echo ('<p>Query being run</p>') , . , , .

, , xdebug, , .

+1
source

Is there a chance that there are triggers in the table ?

SHOW TRIGGERS LIKE 'banner%'\G
+1
source

I had this exact problem and narrowed down to the following CSS code:

body {
   background-image:url();
}

If the image URL is not specified for background-image, it forces the entire page to reload in some browsers (as described here ). I had a problem with Chrome (v23), but not with IE 10.

0
source

Source: https://habr.com/ru/post/1781853/


All Articles