php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rschuetz at hmcw dot de
New email:
PHP Version: OS:

 

 [2018-11-23 08:50 UTC] rschuetz at hmcw dot de
Description:
------------
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'");
	var_dump($link);
	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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-12 18:44 UTC] dharman@php.net
-Status: Open +Status: Duplicate
 [2021-01-12 18:44 UTC] dharman@php.net
Duplicate of Bug #67348	Reading $dbc->stat modifies $dbc->affected_rows
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 20:01:29 2024 UTC