gpt4 book ai didi

PHP MySQL UPDATE 查询不起作用(没有返回行)

转载 作者:行者123 更新时间:2023-11-29 13:50:40 25 4
gpt4 key购买 nike

我在 PHP 中使用 MySQL 函数的 UPDATE 查询时遇到问题。我没有犯任何语法错误,但它根本不返回任何行(我正在回显结果行,它总是显示 0)。我的代码如下:

mysql_query("UPDATE wecode.users SET activate = 1 WHERE username = '$username' AND password = '$password' AND email = '$email'", $connection)
or die ("Troubles activating the account ".mysql_error());
return mysql_affected_rows();

我尝试将相同的查询(使用实际列的值)放入我的工作台中,并且效果很好(至少查询返回 1 个结果行)。那么,知道问题出在哪里吗?

最佳答案

不要使用mysql_affected_rows来指示用户已被此查询激活。

如果用户不存在或用户已激活 (activate=1),它将返回 0。

PHP Manual - mysql_affected_rows :

When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.

关于PHP MySQL UPDATE 查询不起作用(没有返回行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16726632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com