php - 'insert into ... on duplicate key' with auto increment -



php - 'insert into ... on duplicate key' with auto increment -

i trying insert if combination of 2 columns (a , b) not exist already. otherwise, want update. issue of next code inserts new row instead of updating when want to. reason think, because don't manage have kind of two-unique-column in settings of table. 1 have solution? google doesn't seem friend today..

the table:

id : int, primary, ai b c , d : int

the code:

$req = $connexion -> prepare(" insert position (a,b,c,d) values (:a,:b,:c,:d) on duplicate key update c=:c;"); $position->bindparam(':a', $a); $position->bindparam(':b', $b); $position->bindparam(':c', $c); $position->bindparam(':d', $d); $a = $val_a; $b = $val_b; $c = $val_c; $d = $val_d; $req -> execute();

on duplicate key requires unique key if not matching primary key. can add together unique key using alter table query

alter table position add together unique key (a,b)

php sql on-duplicate-key

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -