Pdo:exec () A question about the return value

Source: Internet
Author: User
Pdo::exec () The return value of the problem.
Set script run time to unlimited
Set_time_limit (0);

Create a pgsql connection with PDO
try {
$pgLink = new PDO (' Pgsql:host=localhost port=5432 dbname=db2 user=root password=111111 ');
}catch (Exception $e) {
echo $e->getmessage ();
}

Defining SQL Modification Statements
$sql = "UPDATE trade.membership SET gender=1, birth_type=0, name= ' wsy ', birthday= ' 2011-01-01 ', email= ', join_date= ' 2011 -01-02 ', Status=1, address= ' aaaa ', id_number= ' 25454 ', postcode= ' 100031 ', phone= ' 666 ', type_id=1 WHERE mobile= ' 110 '; ";

Execute SQL statement
$result = $pgLink->exec ($sql);

Output SQL Results
echo $result. ' '. $sql;

Output Result:
1 UPDATE trade.membership SET gender=1, birth_type=0, name= ' wsy ', birthday= ' 2011-01-01 ', email= ', join_date= ' 2011-01-02 ', Status=1, address= ' aaaa ', id_number= ' 25454 ', postcode= ' 100031 ', phone= ' 666 ', type_id=1 WHERE mobile= ' 110 ' ;

The problem is this:
This table has no mobile= ' 110 ' this line, the $SQL statement to the local SQL Server run is also "0 affected rows."
But why is the result in the program "1"? The output of pdo::exec () should not be the number of rows affected by adding or deleting.

------Solution--------------------
This should be a bug of PDO, which can be processed correctly using preprocessing and Pdo::rowcount ().
  • Related Article

    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.