Skip to content

Commit 64b5a57

Browse files
authored
Merge pull request #501 from Ettemlevest/master
Adding error number to exception
2 parents 0f0ca57 + 3221f24 commit 64b5a57

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

MysqliDb.php

Lines changed: 9 additions & 6 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

@@ -1770,8 +1772,9 @@ protected function _prepareQuery()
17701772
{
17711773
if (!$stmt = $this->mysqli()->prepare($this->_query)) {
17721774
$msg = $this->mysqli()->error . " query: " . $this->_query;
1775+
$num = $this->mysqli()->errno;
17731776
$this->reset();
1774-
throw new Exception($msg);
1777+
throw new Exception($msg, $num);
17751778
}
17761779

17771780
if ($this->traceEnabled) {
@@ -2284,4 +2287,4 @@ private function conditionToSql($operator, $val) {
22842287
}
22852288
}
22862289

2287-
// END class
2290+
// END class

0 commit comments

Comments
 (0)