|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77188 mysqli_affected_rows unexpectedly returning -1
Submitted: 2018-11-23 08:50 UTC Modified: 2021-01-12 18:44 UTC
From: rschuetz at hmcw dot de Assigned:
Status: Duplicate Package: MySQLi related
PHP Version: 7.2.12 OS: Xubuntu 18.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rschuetz at hmcw dot de
New email:
PHP Version: OS:


 [2018-11-23 08:50 UTC] rschuetz at hmcw dot de
I insert or update a row of a mysql table via mysqli_query. Then I try to get the number of affected rows via mysqli_affected_rows. It returns 1. Everything works fine so far. Then I dump the mysqli object via var_dump or print_r between the mysqli_query and mysqli_affected_rows calls.

Test script:
$link = mysqli_connect($my_host, $my_username, $my_password, $my_dbname);

if ($link)
	mysqli_query($link, "create table `test` (`id` int not null auto_increment, `name` varchar(100) not null, primary key (`id`)) engine = MyISAM charset = utf8mb4 collate utf8mb4_general_ci");
	mysqli_query($link, "insert into `test` set `name` = 'Al Bundy'");
	echo 'affected rows = ' . mysqli_affected_rows($link) . "\n";
	echo 'sqlstate error = ' . mysqli_sqlstate($link) . "\n";

Expected result:
I expected mysqli_affected_rows to return 1 because a dump of the mysqli object shouldn't change anything about its internal state.

Actual result:
But mysqli_affected_rows unexpectedly returns -1. mysqli_sqlstate doesn't show any error, returning '00000'.

I didn't experience this behavior if I use prepared statements and mysqli_stmt_affected_rows.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-12 18:44 UTC]
-Status: Open +Status: Duplicate
 [2021-01-12 18:44 UTC]
Duplicate of Bug #67348	Reading $dbc->stat modifies $dbc->affected_rows
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 01 07:03:34 2021 UTC