I'm trying to use both REPLACE
and SET
in a query, whithout any succes!
Error message:
Unknown system variable 'c3'
What am i doing wrong?
PHP
$query = "SET NEW.c3 = CONCAT(OLD.c3, NEW.:c3);
REPLACE INTO table(
c1,
c2,
c3)
VALUES(
:c1,
:c2,
:c3)";
$query_params = array(
':c1' => $c1,
':c2' => $c2,
':c3' => $c3);
My guess is you want to insert a new row or update the existing one (if it already exists in the table). If this is the case then the correct query is:
INSERT INTO table(c1, c2, c3) VALUES
(:c1, :c2, :c3)
ON DUPLICATE KEY UPDATE
c3 = CONCAT(c3, :c3);
or, if you want to insert/update many rows at once:
INSERT INTO table(c1, c2, c3) VALUES
(:c1, :c2, :c3),
(:d1, :d2, :d3),
(:e1, :e2, :e3)
ON DUPLICATE KEY UPDATE
c3 = CONCAT(c3, VALUES(c3));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments