PHP PDO related: Update SQL statement not updating the content of the database

后端 未结 4 364
渐次进展
渐次进展 2021-01-24 05:21

I am trying to implement an update statement using a prepared statement in a PHP script, but it appears that it is not updating the record in the database and I am not sure why

相关标签:
4条回答
  • 2021-01-24 05:28

    I'm not sure if you want to do what you're trying to do.

    Your UPDATE statement basically says update the key and two values based on the NEW value, since party_id is in the SET and WHERE clauses.

    You may want to change your prepared statement to this:

    UPDATE DatTable SET DF_PARTY_ID = :party_id, DF_PARTY_CODE = :party_code, DF_CONNECTION_ID = :connection_id WHERE DF_PARTY_ID = ':old_party_id'

    bind your NEW party_id value to :party_id and the CURRENT one to :old_party_id

    0 讨论(0)
  • 2021-01-24 05:28

    Instead of guessing, basic error handling must be implemented:

    $arr = $stmt->errorInfo();
    print_r($arr);
    
    0 讨论(0)
  • 2021-01-24 05:42

    Might not help, but why are you only binding 3 variables, when there are 4? I can't say that I have experience doing this in PHP, but in Perl and Oracle it would throw an error. I'd try binding the 2 SETs and the 1 WHERE, and removing the first assignment, and see if that works.

    0 讨论(0)
  • 2021-01-24 05:47

    Make sure that the party_id you are trying to update exists in the database.

    Also, if your table is InnoDB, make sure that you have autocommit on or issue an explicit commit after the update is made.

    0 讨论(0)
提交回复
热议问题