Skip to content

Commit 0890ad9

Browse files
author
Nagy Imre
committed
adding support for error codes
1 parent f724dff commit 0890ad9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

MysqliDb.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ class MysqliDb
106106
*/
107107
protected $_stmtError;
108108

109+
/**
110+
* Variable which holds last statement error number
111+
*
112+
* @var int
113+
*/
114+
protected $_stmtErrno;
115+
109116
/**
110117
* Database credentials
111118
* @var string
@@ -393,6 +400,7 @@ public function rawQuery($query, $bindParams = null)
393400
$stmt->execute();
394401
$this->count = $stmt->affected_rows;
395402
$this->_stmtError = $stmt->error;
403+
$this->_stmtErrno = $stmt->errno;
396404
$this->_lastQuery = $this->replacePlaceHolders($this->_query, $params);
397405
$res = $this->_dynamicBindResults($stmt);
398406
$this->reset();
@@ -464,6 +472,7 @@ public function query($query, $numRows = null)
464472
$stmt = $this->_buildQuery($numRows);
465473
$stmt->execute();
466474
$this->_stmtError = $stmt->error;
475+
$this->_stmtErrno = $stmt->errno;
467476
$res = $this->_dynamicBindResults($stmt);
468477
$this->reset();
469478

@@ -555,6 +564,7 @@ public function get($tableName, $numRows = null, $columns = '*')
555564

556565
$stmt->execute();
557566
$this->_stmtError = $stmt->error;
567+
$this->_stmtErrno = $stmt->errno;
558568
$res = $this->_dynamicBindResults($stmt);
559569
$this->reset();
560570

@@ -676,6 +686,7 @@ public function update($tableName, $tableData, $numRows = null)
676686
$status = $stmt->execute();
677687
$this->reset();
678688
$this->_stmtError = $stmt->error;
689+
$this->_stmtErrno = $stmt->errno;
679690
$this->count = $stmt->affected_rows;
680691

681692
return $status;
@@ -707,6 +718,7 @@ public function delete($tableName, $numRows = null)
707718
$stmt = $this->_buildQuery($numRows);
708719
$stmt->execute();
709720
$this->_stmtError = $stmt->error;
721+
$this->_stmtErrno = $stmt->errno;
710722
$this->reset();
711723

712724
return ($stmt->affected_rows > 0);
@@ -1037,6 +1049,7 @@ private function _buildInsert($tableName, $insertData, $operation)
10371049
$stmt = $this->_buildQuery(null, $insertData);
10381050
$status = $stmt->execute();
10391051
$this->_stmtError = $stmt->error;
1052+
$this->_stmtErrno = $stmt->errno;
10401053
$haveOnDuplicate = !empty ($this->_updateColumns);
10411054
$this->reset();
10421055
$this->count = $stmt->affected_rows;
@@ -1583,6 +1596,15 @@ public function getLastError()
15831596
return trim($this->_stmtError . " " . $this->mysqli()->error);
15841597
}
15851598

1599+
/**
1600+
* Method returns mysql error number
1601+
*
1602+
* @return int
1603+
*/
1604+
public function getLastErrno () {
1605+
return $this->_stmtErrno;
1606+
}
1607+
15861608
/**
15871609
* Mostly internal method to get query and its params out of subquery object
15881610
* after get() and getAll()

0 commit comments

Comments
 (0)