|  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: -
From: rschuetz at hmcw dot de Assigned:
Status: Open Package: MySQLi related
PHP Version: 7.2.12 OS: Xubuntu 18.04
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 20 15:01:25 2020 UTC