From 0cc5ca4916c661f56a8920bca8b1f3ef94971e14 Mon Sep 17 00:00:00 2001 From: Ettemlevest Date: Wed, 13 Jul 2016 10:39:04 +0200 Subject: [PATCH 1/2] Adding error number to exception Adding mysqli error number to exception in _prepareQuery method --- MysqliDb.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MysqliDb.php b/MysqliDb.php index 1c7005a6..fe88dead 100644 --- a/MysqliDb.php +++ b/MysqliDb.php @@ -1770,8 +1770,9 @@ protected function _prepareQuery() { if (!$stmt = $this->mysqli()->prepare($this->_query)) { $msg = $this->mysqli()->error . " query: " . $this->_query; + $num = $this->mysqli()->errno; $this->reset(); - throw new Exception($msg); + throw new Exception($msg, $num); } if ($this->traceEnabled) { @@ -2284,4 +2285,4 @@ private function conditionToSql($operator, $val) { } } -// END class \ No newline at end of file +// END class From 3221f2482b7d0ec33817510a29ef3407e6fa26ec Mon Sep 17 00:00:00 2001 From: Ettemlevest Date: Wed, 13 Jul 2016 12:00:17 +0200 Subject: [PATCH 2/2] More error numbers in exceptions More exception gets mysql error number with the second parameter: connect() queryUnprepared() lock() unlock() --- MysqliDb.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/MysqliDb.php b/MysqliDb.php index fe88dead..b6fd491b 100644 --- a/MysqliDb.php +++ b/MysqliDb.php @@ -281,7 +281,7 @@ public function connect() $this->_mysqli = new mysqli($this->host, $this->username, $this->password, $this->db, $this->port); if ($this->_mysqli->connect_error) { - throw new Exception('Connect Error ' . $this->_mysqli->connect_errno . ': ' . $this->_mysqli->connect_error); + throw new Exception('Connect Error ' . $this->_mysqli->connect_errno . ': ' . $this->_mysqli->connect_error, $this->_mysqli->connect_errno); } if ($this->charset) { @@ -408,7 +408,7 @@ private function queryUnprepared($query) // Failed? if(!$stmt){ - throw new Exception("Unprepared Query Failed, ERRNO: ".$this->mysqli()->errno." (".$this->mysqli()->error.")"); + throw new Exception("Unprepared Query Failed, ERRNO: ".$this->mysqli()->errno." (".$this->mysqli()->error.")", $this->mysqli()->errno); }; // return stmt for future use @@ -1136,6 +1136,7 @@ public function lock($table) // Exceute the query unprepared because LOCK only works with unprepared statements. $result = $this->queryUnprepared($this->_query); + $errno = $this->mysqli()->errno; // Reset the query $this->reset(); @@ -1148,7 +1149,7 @@ public function lock($table) } // Something went wrong else { - throw new Exception("Locking of table ".$table." failed"); + throw new Exception("Locking of table ".$table." failed", $errno); } // Return the success value @@ -1169,6 +1170,7 @@ public function unlock() // Exceute the query unprepared because UNLOCK and LOCK only works with unprepared statements. $result = $this->queryUnprepared($this->_query); + $errno = $this->mysqli()->errno; // Reset the query $this->reset(); @@ -1180,7 +1182,7 @@ public function unlock() } // Something went wrong else { - throw new Exception("Unlocking of tables failed"); + throw new Exception("Unlocking of tables failed", $errno); }