sql语句成功,改变行数却为0???

WBOY
Release: 2016-06-06 20:42:26
Original
1378 people have browsed it

<code>$query="update table_user set balance=balance+'$money' where name='$name'";
$result=$mysqli->query($query);
echo $result;
echo "<br>";
echo $mysqli->affected_rows;
</code>
Copy after login
Copy after login

数据库已经连接成功,上面的代码执行后echo $result输出为1,表示操作成功,,但是echo $mysqli->affected_rows输出为0,表示失败,,怎么会这样,问题在哪????

提示:如果先在mysql的客户端执行一下一个记录的更新语句,则在php中就可以继续更新,且成功,没有在mysql客户端执行的记录则不成功。

回复内容:

<code>$query="update table_user set balance=balance+'$money' where name='$name'";
$result=$mysqli->query($query);
echo $result;
echo "<br>";
echo $mysqli->affected_rows;
</code>
Copy after login
Copy after login

数据库已经连接成功,上面的代码执行后echo $result输出为1,表示操作成功,,但是echo $mysqli->affected_rows输出为0,表示失败,,怎么会这样,问题在哪????

提示:如果先在mysql的客户端执行一下一个记录的更新语句,则在php中就可以继续更新,且成功,没有在mysql客户端执行的记录则不成功。

操作成功不代表你 更改了 任何东西. 你的sql里 where条件可以匹配到么. 还有确保你的$money 不为0

<code>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: 0

mysql> 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
</code>
Copy after login

这两条都query OK, 但是0 rows affected

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!