Solution for :Insert into a MySQL table or update if exists
If I want to add a row to a database table, but if a row exists with the same unique key I want to update the row.
For example:
1 | insert into table (id, name , age) values (1, "A" , 20) |
Let’s say the unique key is id
, and in my database there is a row with id = 1
. In that case I want to update that row with these values. Normally this gives an error. If I use insert IGNORE
it will ignore the error, but it still won’t update.
We can use INSERT ... ON DUPLICATE KEY UPDATE
QUERY:
1 2 | INSERT INTO table (id, name , age) VALUES (1, "A" , 20) ON DUPLICATE KEY UPDATE name = "A" , age=20 |
sir I wan to purchse the Category and Taxonomy Image plugin for my woo com website, but plesee tell me can I use the plugin on wordpress running on php 7.1?
ReplyDelete@Ahmed.. Thank you
ReplyDelete