Skip to content

Commit 3221f24

Browse files
author
Ettemlevest
authored
More error numbers in exceptions
More exception gets mysql error number with the second parameter: connect() queryUnprepared() lock() unlock()
1 parent 0cc5ca4 commit 3221f24

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

MysqliDb.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public function connect()
281281
$this->_mysqli = new mysqli($this->host, $this->username, $this->password, $this->db, $this->port);
282282

283283
if ($this->_mysqli->connect_error) {
284-
throw new Exception('Connect Error ' . $this->_mysqli->connect_errno . ': ' . $this->_mysqli->connect_error);
284+
throw new Exception('Connect Error ' . $this->_mysqli->connect_errno . ': ' . $this->_mysqli->connect_error, $this->_mysqli->connect_errno);
285285
}
286286

287287
if ($this->charset) {
@@ -408,7 +408,7 @@ private function queryUnprepared($query)
408408

409409
// Failed?
410410
if(!$stmt){
411-
throw new Exception("Unprepared Query Failed, ERRNO: ".$this->mysqli()->errno." (".$this->mysqli()->error.")");
411+
throw new Exception("Unprepared Query Failed, ERRNO: ".$this->mysqli()->errno." (".$this->mysqli()->error.")", $this->mysqli()->errno);
412412
};
413413

414414
// return stmt for future use
@@ -1136,6 +1136,7 @@ public function lock($table)
11361136

11371137
// Exceute the query unprepared because LOCK only works with unprepared statements.
11381138
$result = $this->queryUnprepared($this->_query);
1139+
$errno = $this->mysqli()->errno;
11391140

11401141
// Reset the query
11411142
$this->reset();
@@ -1148,7 +1149,7 @@ public function lock($table)
11481149
}
11491150
// Something went wrong
11501151
else {
1151-
throw new Exception("Locking of table ".$table." failed");
1152+
throw new Exception("Locking of table ".$table." failed", $errno);
11521153
}
11531154

11541155
// Return the success value
@@ -1169,6 +1170,7 @@ public function unlock()
11691170

11701171
// Exceute the query unprepared because UNLOCK and LOCK only works with unprepared statements.
11711172
$result = $this->queryUnprepared($this->_query);
1173+
$errno = $this->mysqli()->errno;
11721174

11731175
// Reset the query
11741176
$this->reset();
@@ -1180,7 +1182,7 @@ public function unlock()
11801182
}
11811183
// Something went wrong
11821184
else {
1183-
throw new Exception("Unlocking of tables failed");
1185+
throw new Exception("Unlocking of tables failed", $errno);
11841186
}
11851187

11861188

0 commit comments

Comments
 (0)