A validating SQL lexer and parser with a focus on MySQL dialect.
Please use Composer to install:
composer require phpmyadmin/sql-parser
Command line utility to syntax highlight SQL query:
./vendor/bin/highlight-query --query "SELECT 1"Command line utility to lint SQL query:
./vendor/bin/lint-query --query "SELECT 1"echo SqlParser\Utils\Formatter::format($query, array('type' => 'html'));
$parsed = new SqlParser\Parser($query); // you can now inspect or change query var_dump($parser->statements[0]); // and build it again $statement = $parser->statements[0]; $statement->build()
This library was originally created during the Google Summer of Code 2015 and has been used by phpMyAdmin since version 4.5.