Here is the request itself

$query = ("REPLACE INTO`" . DB_PREFIX . "archive_sum_back_newposhta` SET name_sender = '" . $this->db->escape($list_data[$key]['name_sender']). "', sum_back = '" . $this->db->escape($list_data[$key]['sum_back']) . "' "); 

fields in the database

 id_archive int(11) AUTO_INCREMENT PRIMARY KEY name_sender varchar(255) UNIQUE sum_back varchar(255) 

When so the records are not duplicated but the id changes (that is, there were 2 entries id = 1, id = 2 and after adding repeated entries id changed to id = 3 id = 4) how to fix that id would change?

  • 2
    Give a specific generated query, not a constructor. And the data set in the database that it affects. - PinkTux
  • one
    Use insert ... on duplicate key update instead of replace - Mike
  • Thank you for helping insert ... on duplicate key update is what you need - Roman Yushko

1 answer 1

I will duplicate my answer from the English-language site

For Mysql, 3 scenarios are possible when a primary key double is encountered.

If we want