We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Query does wrong thigs

I am trying to execute this siple query:

  • $update = $this->modelsManager->executeQuery("UPDATE Country SET active = '1' WHERE cc_fips = '$enteredcountry'");

But i get thiss error:

  • SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'FI' for key 'cc_fips'

I have logged the query , and it is this one :

  • INSERT INTO country (cc_fips, cc_iso, tld, country_name, active) VALUES (?, ?, ?, ?,

Why is it inserting a new record instead of updating the selected one?



8.6k

Are you sure you are logging the correct query? Because it doesn't seem so.



17.0k
Accepted
answer

I have had en error in my database : my unique value vas set to accept zero values. Whatever.... I have lost 3 days on this issue... I'm totally frustrated :D

UPDATE Country SET Country.active = '1' WHERE Country.cc_fips = '$enteredcountry'