Using PDO Prepared Statement and Incrementing a column value

后端 未结 2 1112
情书的邮戳
情书的邮戳 2021-01-13 19:06

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
(

          


        
2条回答
  •  再見小時候
    2021-01-13 19:25

    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 = ? )   
    

提交回复
热议问题