|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-08-03 17:26 UTC] 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(); } } PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
To test issue just call the query passing a statement with SQL syntax error. $db->query("DROP TABLE IF EXISTS xyz `oc_rwd_category`;");