Bug #72748 [Fbk->NoF]: MySQLi error variables gets cleared executing any line of code after query
Edit report at https://bugs.php.net/bug.php?id=72748&edit=1
ID: 72748
Updated by: php-bugs@lists.php.net
Reported by: mdutra at mdisys dot net
Summary: MySQLi error variables gets cleared executing any line
of code after query
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: MySQLi related
Operating System: CENTOS 6.8 x86_64
PHP Version: 7.0.9
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2017-05-10 13:39:31] fjanisze@php.net
Hi, can I ask you to attempt to reproduce this issue with the latest environment releases? We do
have the suspect that this issue shall not appear anymore, indeed I'm not able to reproduce it
locally.
------------------------------------------------------------------------
[2016-08-03 17:35:30] mdutra at mdisys dot net
To test issue just call the query passing a statement with SQL syntax error.
$db->query("DROP TABLE IF EXISTS xyz oc_rwd_category;");
------------------------------------------------------------------------
[2016-08-03 17:26:34] mdutra at mdisys dot net
Description:
------------
---
From manual page: http://www.php.net/mysqli.error
---
I have consistently reproduced this issue in WAMP development and LAMP PHP7 production environments.
When mysqli executes a query with sql syntax error it returns the errno, error and error_list
values; but immediately after executing another line of code (any code at all) these values are
cleared making it impossible to return the error number and description. I've tried several
alternatives to retrieve these error values to no use. It is most likely a PHP 7 MySQLi driver
issue.
Test script:
---------------
<?php
namespace DB;
final class MySQLi {
private $connection;
public function __construct($hostname, $username, $password, $database, $port = '3306') {
$this->connection = new \mysqli($hostname, $username, $password, $database, $port);
if ($this->connection->connect_error) {
throw new \Exception('Error: ' . mysql_error($this->connection) . '<br
/>Error No: ' . mysql_errno($this->connection) . '<br /> Error in:
<b>' . $trace[1]['file'] . '</b> line <b>' .
$trace[1]['line'] . '</b><br />' . $sql);
}
$this->connection->set_charset("utf8");
$this->connection->query("SET SQL_MODE = ''");
}
public function query($sql) {
$query = $this->connection->query($sql);
//*** Test line to prove any line of code executed does wipe off the error variables
values.
$errmsg = $this->connection->error;
if ($query) {
if ($query instanceof \mysqli_result) {
$data = array();
while ($row = $query->fetch_assoc()) {
$data[] = $row;
}
$result = new \stdClass();
$result->num_rows = $query->num_rows;
$result->row = isset($data[0]) ? $data[0] : array();
$result->rows = $data;
$query->close();
return $result;
} else {
return true;
}
} else {
throw new \Exception('Error: ' . $this->connection->error . '<br
/>Error No: ' . $this->connection->errno . '<br />' . $sql);
}
}
public function escape($value) {
return $this->connection->real_escape_string($value);
}
public function countAffected() {
return $this->connection->affected_rows;
}
public function getLastId() {
return $this->connection->insert_id;
}
public function connected() {
return $this->connection->connected();
}
public function __destruct() {
$this->connection->close();
}
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72748&edit=1
Thread (4 messages)