Skip to content

Parsing MySQL error messages to structured format

License

Notifications You must be signed in to change notification settings

badoo/mysql-error-parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MySQL error parser

This lib provides regex patterns for all mysql server errors from version 5.5 to 8.0.
It can be used for extracting detailed information from your mysql errors and future analisys.

Usage example

$connect = new \mysqli('localhost', 'root', '');
$result = $connect->query('select * from db.unknown_table');
if (!$result) {
    $parser = new \Solodkiy\MysqlErrorsParser\PatternMatcher();
    $structuredError = $parser->matchError($connect->errno, $connect->error);
    var_dump(
        $connect->error, 
        $structuredError->getTemplate(), 
        $structuredError->getParams()
    );
}

Result

string(38) "Table 'db.unknown_table' doesn't exist"
string(34) "Table '{db}.{table}' doesn't exist"
array(2) {
  'db' => string(2) "db"
  'table' => string(13) "unknown_table"
}

Install

composer require solodkiy/mysql-error-parser

About

Parsing MySQL error messages to structured format

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 94.1%
  • PHP 5.9%