Closed KirDE closed 3 years ago
Since this can be handled at the database configuration level, I think there's no need to bloat the database interaction layer. Keeping it in the database config allows you more flexibility, such as the option to log it to a file/table etc.
you misunderstoo d the request. it is about logging invalid / failed queries. MySQL doesn't log invalid/failed queries anywhere. http://stackoverflow.com/questions/4631133/mysql-log-of-invalid-queries
We create a simple medoo wrapper include monolog logging. Create a class named "Database", extends Medoo and overwrite methods like:
public function insert($table, $data) {
$this->logger->info( 'insert', ["table" => $table, "data" => $data] );
return parent::insert($table, $data);
}
So for error logging, I write a errorHandler: Query/Exec method:
public function query($query, $context = []) {
$this->logger->info('query', $context);
$result = parent::query($query);
$this->handleSqlError( $result ); // <-- handle errors
return $result;
}
Error handling:
private function handleSqlError($query) {
$error = $this->error();
if ($error[0] != '00000') {
$this->logger->critical('ERROR', ["sql" => $query,"error" => $error]);
}
}
one flag to enable logging (into file) of all database errors.