I\'ve read this thread: Issues incrementing a field in MySQL/PHP with prepared statements but didn\'t see the answer to my problem.
PDOStatement Object
(
Using parameters is not just a simple text replacement. You can't replace a column name with a parameter. MySQL will interpret your query as if you had written this:
UPDATE user_alerts SET notif = 'notif' + 2 WHERE ( user_id = ? )
The string 'notif'
is converted to zero for the addition.
Try this query instead:
UPDATE user_alerts SET notif = notif + 2 WHERE ( user_id = ? )
$sql = 'UPDATE user_alerts SET notif = notif + 2 WHERE ( user_id = :userid )';
$prepStatement = $pdo->prepare( $sql );
$prepStatement->execute(array(':userid' => $userid));
You can't bind a column name to a prepared statement.