Open
Conversation
I've been into a requirement from my job, and i think this works well and I suppose that are other colleagues that would use this functions so they save all the error data related to MySQLi so here is my contribution to this excellent library
methods:
Main function to generate the error from querys:
errorTrack($insertData = null,$case_err="")
Function that help us to populate our file with all the data recolected from errorTrack function
private function createLog($data)
Properties:
//Boolean variable to set the errorTrack method
protected $errTrack = false;
//String variable to set the route where the file will be created
protected $routeTrack;
Example of use
/**
* Execute sql sentence with parameters
* @param string $sql SQL sentence
* @param array $params All parameters necessary for the query
*
* @return int Result
* */
public static function execute($sql,$params){
//Set the errorTrack method
self::getInstance()->setErrTrack(true);
//Execute Query
$result = self::getInstance()->rawQuery($sql, $params);
//Return result
return $result;
}
This methods and properties have been tested with INSERT,UPDATE,DELETE sentences working OK.
Now the query shows all the parameters in its place, insted of ? symbols in the query.
It was showing the mysqli->error twice! Now it is corrected
|
I think it's nice that you think about that, but logging is something for a new class.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've been into a requirement from my job, and I think this works well and I suppose that are other colleagues that would use this functions so they save all the error data related to MySQLi so here is my contribution to this excellent library
methods:
Main functions to generate the error from querys:
Properties:
//Boolean variable to set the errorTrack method
protected $errTrack = false;
//String variable to set the route where the file will be created
protected $routeTrack;
//String variable to set the catched error
protected $errMsg = '';
Function that help us to populate our file with all the data recolected from errorTrack function
/**
* 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
*/
/**
* Save errors into a file
* @param bool $enabled Allow create file to save errors
* @param string $route Set a route to create this file
*/
/**
* Reset states after an execution
*
* @return object Returns the current instance.
*/
...
}
Example of use
/**
* Execute sql sentence with parameters
* @param string $sql SQL sentence
* @param array $params All parameters necessary for the query
*
* @return int Result
* */
This methods and properties have been tested with INSERT,UPDATE,DELETE sentences working OK.