Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions MysqliDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ class MysqliDb
protected $traceStripPrefix;
public $trace = array();

/**
* Variable for error tracking
*/
protected $errTrack = false;
protected $routeTrack;
protected $errMsg = '';

/**
* @param string $host
* @param string $username
Expand Down Expand Up @@ -227,6 +234,37 @@ public static function getInstance()
return self::$_instance;
}


/**
* Save errors into a file
* @param bool $enabled Allow create file to save errors
* @param string $route Set a route to create this file
*/
public function setErrTrack($enabled,$route=""){
$this->errTrack = $enabled;

// "/var/www/html/inc/libs/";
$this->routeTrack = $route;
}

/**
* Internal function to create a .txt file to save all the log
* collected from an specific query
* @param [type] $data Data that is going to be written in the file
*/
protected function createLog($data){

//Guardamos directorio actual
$actual = getcwd();

$file = $this->routeTrack."mysqli_errors.txt";

$fh = fopen($file, 'a') or die("Can't open/create file");
fwrite($fh,$data);
fclose($fh);

}

/**
* Reset states after an execution
*
Expand All @@ -237,6 +275,18 @@ protected function reset()
if ($this->traceEnabled)
$this->trace[] = array ($this->_lastQuery, (microtime(true) - $this->traceStartQ) , $this->_traceGetCaller());

if($this->errTrack && $this->_mysqli->error != NULL){

//Put the MySQLi errno in order to complement the error info
$this->errMsg = date("Y-m-d h:i:s ").'MySQLi errno: '.
$this->_mysqli->errno.' - '.
$this->_mysqli->error." \nQuery: ".
$this->_lastQuery."\n\n";

$this->createLog($this->errMsg);

}

$this->_where = array();
$this->_join = array();
$this->_orderBy = array();
Expand Down Expand Up @@ -1192,6 +1242,7 @@ protected function replacePlaceHolders ($str, $vals) {
$str = substr ($str, $pos + 1);
}
$newStr .= $str;

return $newStr;
}

Expand Down