Hey guys i try to get this query with PDO but not achieved so far , so it might be the comma my problem ( ‘,’ ) what you think? what i just try to do is in a field with decimal number or decimal numbers comma separated subtract one value in that string managing of course the comma (delete from the beginning or end). Also would be useful changing the query if necessary
$query = "UPDATE table SET field_to_change = SUBSTR(REPLACE(CONCAT(',' , field_to_change, ','), ':userid', ','), 2, LENGTH(REPLACE(CONCAT(',', field_to_change, ','), ':userid', ',')) - 2) WHERE field_id = :ownid ";
$conn = New PDO ...
$user_with_comma = ','.$value.','
$sql = conn->prepare($query);
$sql->bindValue(':userid', $user_with_comma , PDO::PARAM_STR);
$sql->bindValue(':ownid', $value2 , PDO::PARAM_INT);
$sql->execute();
i also try
$query = "UPDATE table SET field_to_change = SUBSTR(REPLACE(CONCAT(',' , field_to_change, ','), ', :userid ,', ','), 2, LENGTH(REPLACE(CONCAT(',', field_to_change, ','), ', :userid ,', ',')) - 2) WHERE field_id = :ownid ";
$sql->bindValue(':userid', $value , PDO::PARAM_INT);
it always gave me the “number of bound variables does not match number of tokens” error .
thank you in advance for any help
You cannot reuse parameter tokens that way. Give the first two separate names and assign them the same value:
then: