mysqli_affected_rows()返回-1,但查询有效 [英] mysqli_affected_rows() returns -1 but query works
问题描述
我所有的mysql函数似乎都存在此问题.简单的insert语句有效,但是当我检查受影响的行时,它返回-1
.
All my mysql functions seem to be having this problem. The simple insert statement works, but when I check the affected rows, it returns -1
.
这可行,将新行插入到数据库中,但是调试器将mysqli_affected_rows显示为-1
,因此将运行else块:
This works, a new row is inserted into the database with it, but debugger shows the mysqli_affected_rows as -1
, and therefore the else block gets run:
$query = "INSERT INTO users (email, password) VALUES ('$email', '$password')";
mysqli_query($this->connection, $query) or die('Query failed in register.');
if (mysqli_affected_rows($this->connection)>0) {
//this doesnt get run,
}
else {
// this is run
}
为什么会这样?
- 我正在使用Netbeans,Xdebug,WAMP.
- 创建连接后立即查看连接时,受影响的行已设置为-1.
- 运行成功的查询后,在执行受影响的行检查之前,连接仍显示-1.
- 在连接对象中没有看到错误消息或错误号.
推荐答案
我遇到了完全相同的问题.我调查了Netbeans和Xdebug的问题,看来这是MySQLi扩展本身的错误.已完成相应的错误报告.同时,您可以改用更宽容的表情,例如
I had exactly the same problem. I've investigated the issue with Netbeans and Xdebug and it seems this is a bug in the MySQLi extension itself. An according bug report has been made. In the meantime you can instead use a more forgiving Expression, e.g.
if (mysqli_sqlstate($dbc) == 00000) {
//your code
}
继续调试剩余的代码.
这篇关于mysqli_affected_rows()返回-1,但查询有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!