PHP-SQLlint: CLI syntax checker for SQL files

I wanted to let our CI system syntax-check SQL files, but failed to find a SQL syntax checker for the command line. There are many online tools to which you can copy&paste your SQL statements, but nobody wants this.

I did not find any cli tools for this task, apart from the 2005 SQLLint prototype written in Prolog.

Instead I found the SQL parser library used by phpMyAdmin and made a wrapper around it: php-sqllint.

It's a standalone .phar file that you can use to check the syntax of SQL files:

$ php-sqllint tests/files/create-missingcomma.sql
Checking SQL syntax of tests/files/create-missingcomma.sql
 Line 3, col 5 at "pid": A comma or a closing bracket was expected.
 Line 3, col 13 at "11": Unexpected beginning of statement.
 Line 3, col 17 at "DEFAULT": Unrecognized statement type.

It has an emacs output mode, and also lets you highlight SQL files on your shell (ANSI colors) and HTML.

$ echo 'SELECT title FROM tools WHERE domain="SQL" LIMIT 1'\
 | php-sqllint --format --highlight html -
SELECT
  title
FROM
  tools
WHERE
  domain = "SQL"
LIMIT 1

Download the .phar or have a look at the sources (github mirror).

Written by Christian Weiske.

Comments? Please send an e-mail.