The SQL statement is successful, but the number of rows changed is 0 ???

Source: Internet
Author: User
{Code ...} the database has been connected successfully. After the above code is executed, the echo $ result output is 1, indicating that the operation is successful, but the echo $ mysqli-& amp; gt; affected_rows output is 0, it indicates a failure. How can this problem be solved ???? Tip: If you run the command on the mysql client first...
$query="update table_user set balance=balance+'$money' where name='$name'";$result=$mysqli->query($query);echo $result;echo "
";echo $mysqli->affected_rows;

The database has been connected successfully. After the above code is executedecho $resultIf the output is 1, the operation is successful,echo $mysqli->affected_rowsIf the output is 0, it indicates a failure. How can this problem be solved ????

Tip: If you execute an update statement for a record on the mysql client, you can continue the update in php and the update is successful. If the record is not executed on the mysql client, the update fails.

Reply content:
$query="update table_user set balance=balance+'$money' where name='$name'";$result=$mysqli->query($query);echo $result;echo "
";echo $mysqli->affected_rows;

The database has been connected successfully. After the above code is executedecho $resultIf the output is 1, the operation is successful,echo $mysqli->affected_rowsIf the output is 0, it indicates a failure. How can this problem be solved ????

Tip: If you execute an update statement for a record on the mysql client, you can continue the update in php and the update is successful. If the record is not executed on the mysql client, the update fails.

Successful operations do not mean you have changed anything. Can the where condition in your SQL match? Make sure that your $ money is not 0

mysql> update yanse set sexi_id=sexi_id+1 where id=1234342341;Query OK, 0 rows affected (0.00 sec)Rows matched: 0  Changed: 0  Warnings: 0mysql> update yanse set sexi_id=sexi_id where id=1;Query OK, 0 rows affected (0.00 sec)Rows matched: 1  Changed: 0  Warnings: 0

Both query OK, but 0 rows affected

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.