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
.
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
}
Why would this happen?
Edit:
- I'm using Netbeans, Xdebug, WAMP.
- When I view the connection immediately after it is created, the affected rows is already set to -1.
- After running a successful query, the connection still shows -1, before doing the affected rows check.
- No error messages or error numbers are seen in the connection object.
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.
to continue debugging your remaining code.