![]() |
I would like to execute the following SQL in the query builder.
Code: INSERT INTO table1 (`id`, `total`) VALUES (123, 1) ON DUPLICATE KEY UPDATE total = total + 1; We want to execute 1 if the id does not exist and the existing value + 1 if it exists. I tried the code below, but it is not what I expected. PHP Code: $data = [ Generated queries Code: INSERT INTO `table1` (`id`, `total`) VALUES (100,'todal + 1') ON DUPLICATE KEY UPDATE `table1`.`id` = VALUES(`id`), `table1`.`total` = VALUES(`total`) I was hoping for "upsert" to be available after version 4.3, but is that impossible? https://www.codeigniter.com/user_guide/d...rting-data Ultimately, I would like to use "upsertBatch". |
Messages In This Thread |
DUPLICATE KEY UPDATE in the query builder - by chanyui - 09-09-2023, 05:20 AM
RE: DUPLICATE KEY UPDATE in the query builder - by InsiteFX - 09-10-2023, 09:44 PM
RE: DUPLICATE KEY UPDATE in the query builder - by chanyui - 09-11-2023, 01:37 AM
RE: DUPLICATE KEY UPDATE in the query builder - by ozornick - 09-11-2023, 06:45 AM
|