Edit report at https://bugs.php.net/bug.php?id=67348&edit=1
ID: 67348
Comment by: gcognault at free dot fr
Reported by: derick@php.net
Summary: Reading $dbc->stat modifies $dbc->affected_rows
Status: Analyzed
Type: Bug
Package: MySQLi related
Operating System: Linux
PHP Version: 5.6Git-2014-05-27 (Git)
Block user comment: N
Private report: N
New Comment:
I can confirm that this happens in php 7.2.11 as well.
Previous Comments:
------------------------------------------------------------------------
[2018-01-05 14:00:28] steffenbalje at gmail dot com
I can confirm that this happens in php 7.0.22 as well.
------------------------------------------------------------------------
[2017-04-26 13:40:26] fjanisze@php.net
Hello everybody,
the source of all this problem in in $dbc->stat triggering a COM_STATISTICS command to the server
which will update affected_rows to -1. This is expected since no rows were influenced by
COM_STATISTICS so make no sense to keep the old value 1 (or whatever other value we have stored).
Being said that, we're thinking about a removal of the $dbc->stat function which will remove
the trigger of the command to the server, instead $dbc->stat will read the plain value from the
object, this shall fix this problem.
------------------------------------------------------------------------
[2017-01-04 20:29:29] johnnyecon at gmail dot com
Same here.
In my phpunit tests I connect to mysql using mysqli_connect on setUp().
All is ok when the first test runs mysqli_real_escape_string.
But when it is not the first test running then I get the below:
mysqli_real_escape_string(): Couldn't fetch mysqli
I am running PHP7.0 on PHPUnit 5.6.1
------------------------------------------------------------------------
[2016-11-21 12:11:28] aik dot bold at gmail dot com
Happens for me as well on PHP 5.4, PHP 5.5, PHP 5.6. Maybe even on PHP 7.0.
------------------------------------------------------------------------
[2015-08-25 19:40:55] myk at illinois dot edu
I have this problem regardless of whether I step through the code in my Eclipse/Xdebug/MAMP
environment. It seems if I try to open/close mysqli connections when used, the problem occurs. If
I don't close the connections, I get no errors about accessing properties, but I do then get
the expected "too many connections." Any chance this will get fixed soon? It's
really hard to debug when your error logs fill with hundreds of lines of useless info.
if(!$this->db->isConnected()){
$this->db->selectDB();
$this->dbc = $this->db->dbc;
}
$this->resource = $this->dbc->query($this->text);
if($this->resource===false){
$this->error=$this->dbc->connect_error;
if(isset($this->log)){
$err=$this->log->writeLog($this->text."\n".$this->error."\n".$this->implode_r("\n",debug_backtrace()),'log',$tag);
}else{
echo
$this->text."\n".$this->error."\n".$this->implode_r("\n",debug_backtrace()),'log
-- '.$tag;
die;
}
}elseif(strpos($this->text,'insert into')!==false){
$this->result=$this->dbc->insert_id;
}elseif(strpos($this->text,'delete')!==false or
strpos($this->text,'update')!==false){
$this->result=$this->resource;
}else{
$this->fetch_all();
}
$this->dbc->close();
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=67348
--
Edit this bug report at https://bugs.php.net/bug.php?id=67348&edit=1