Commit 7489b650 authored by Alexander Butenko's avatar Alexander Butenko

Add getLastQuery for debugging

parent e24b652a
...@@ -30,6 +30,12 @@ class MysqliDb ...@@ -30,6 +30,12 @@ class MysqliDb
* @var string * @var string
*/ */
protected $_query; protected $_query;
/**
* The previously executed SQL query
*
* @var string
*/
protected $_lastQuery;
/** /**
* An array that holds where joins * An array that holds where joins
* *
...@@ -602,6 +608,7 @@ class MysqliDb ...@@ -602,6 +608,7 @@ class MysqliDb
call_user_func_array(array($stmt, 'bind_param'), $this->refValues($this->_bindParams)); call_user_func_array(array($stmt, 'bind_param'), $this->refValues($this->_bindParams));
} }
$this->_lastQuery = $this->replacePlaceHolders($this->_query, $this->_bindParams);
return $stmt; return $stmt;
} }
...@@ -686,6 +693,30 @@ class MysqliDb ...@@ -686,6 +693,30 @@ class MysqliDb
return $arr; return $arr;
} }
/**
* Function to replace ? with variables from bind variable
* @param string $str
* @param Array $vals
*
* @return string
*/
protected function replacePlaceHolders ($str, $vals) {
$i = 1;
while ($pos = strpos ($str, "?"))
$str = substr ($str, 0, $pos) . $vals[$i++] . substr ($str, $pos + 1);
return $str;
}
/**
* Method returns last executed query
*
* @return string
*/
public function getLastQuery () {
return $this->_lastQuery;
}
/** /**
* Method returns mysql error * Method returns mysql error
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment