Thursday, April 18, 2019

Yii2 Insert On Duplicate Key Update






You are using models in yii, its quite simple .. try to load you model where you suspect to have duplicate entries, if you find the entry the model is loaded else null is return. now if your model is null simply create new model. rest is your normal code to insert a new record.. The on duplicate key update clause can contain multiple column assignments, separated by commas. in assignment value expressions in the on duplicate key update clause, you can use the values(col_name) function to refer to column values from the insert portion of the insert on duplicate key update statement.. The statement above sets the value of the c1 to its current value specified by the expression values(c1) plus 1 if there is a duplicate in unique index or primary key. mysql insert on duplicate key update example. let’s take a look at an example of using the insert on duplicate key update to understand how it works..












On duplicate key update is a mariadb/mysql extension to the insert statement that, if it finds a duplicate unique or primary key, will instead perform an update. the row/s affected value is reported as 1 if a row is inserted, and 2 if a row is updated, unless the api's client_found_rows flag is set.. Check this article yii insert on duplicate update. they suggest you don't use this feature. but i want it to use, so i extended from cdbcommand my own component and add method for on duplicate key update:. The on duplicate key update clause can contain multiple column assignments, separated by commas. in assignment value expressions in the on duplicate key update clause, you can use the values(col_name) function to refer to column values from the insert portion of the insert on duplicate key update statement..



yii2 insert on duplicate key update

visit link reference



No comments:

Post a Comment