PDO EXEC Update

Source: Internet
Author: User
I use the exec update data from PDO to get the number of rows affected
But there is a problem, if the update data is the same as the original data returned is 0
So I can't tell if it's the same as the data update or the data is not updated to the result
You must confirm it again with a query statement
Is there a simpler solution? (As long as the method of pdo,php comes back to the modified state)


Reply to discussion (solution)

Check again for confirmation is not as straightforward as updating

If the update fails, an error occurs
So you should always check the return value of Pdo::errorcode.

Pdo::exec returns 0 indicates that the operation was successful, but no actual action

If the update fails, an error occurs
So you should always check the return value of Pdo::errorcode.

Pdo::exec returns 0 indicates that the operation was successful, but no actual action

EXEC returns three states, updates to data will return an affected number of rows, no update data will return 0, error will return False (the tables that are not in the database are necessarily updated)
The first two states, ErrorCode, return 00000 and cannot be judged at all.

To make my question a little more straightforward.
' User ' database
ID Password
1 boy
Update ' user ' set ' password ' = ' boy ' where ' id ' = ' 1 ';
EXEC returns 0,errorcode return 00000
This would not be good if you told the direct user settings failed.
I would have to select ' Password ' from ' user ' where ' id ' = ' 1 ';
If password== ' boy ' setting succeeds, other settings fail

Uh! So long no one answered!!
Think of a way to do this: Add an Update Time field to the table, and set it to the time of day when you update it
This makes it possible to distinguish between returning and modifying the same data when there is no record in the Update table, which is 0, which requires a query validation problem.
This is a flexible approach, and at the moment it seems the simplest

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.