Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with update + insert in PDO mysql driver #28

Closed
wants to merge 3 commits into from

Conversation

dimasikturbo
Copy link
Contributor

@dimasikturbo dimasikturbo commented Jun 12, 2017

When same data is stored under same key PDO mysql driver return 0 number of updated rows and as a result insert triggers error "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry"

MySQL has a special SQL extension INSERT ON DUPLICATE KEY UPDATE which can be used instead of UPDATE + INSERT.

…ber of updated rows and as a result insert triggers error "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry"

MySQL has a special SQL extension INSERT ON DUPLICATE KEY UPDATE which can be used instead of UPDATE + INSERT.
@coveralls
Copy link

coveralls commented Jun 12, 2017

Coverage Status

Changes Unknown when pulling cbf3a87 on dimasikturbo:master into ** on frqnck:master**.

@frqnck
Copy link
Member

frqnck commented Jun 14, 2017

@dimasikturbo Many thanks for your PR.

Why not add the ON DUPLICATE KEY UPDATE statement directly to $sql_definitions['insert'] ?

e.g.

'insert'    => 'INSERT INTO `%s` (`key`, `data`, `tags`, `expire`, `dated`) VALUES (:key, :data, :tags, :exp, :dated) ON DUPLICATE KEY UPDATE `data`=VALUES(`data`), `tags`=VALUES(`tags`), `expire`=VALUES(`expire`);',

@dimasikturbo
Copy link
Contributor Author

To avoid unnecessary update query for every new entry. But at the same time, usually read/write ratio in cashes is really high, so it might be not a big deal.

@frqnck
Copy link
Member

frqnck commented Jun 19, 2017

hum... I don't think it makes any difference other than adding some extraenous code.

Thank you for the contrib -- I will merge.

@frqnck frqnck closed this Jun 19, 2017
@frqnck frqnck reopened this Jun 19, 2017
@frqnck frqnck closed this Jun 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants