Command line tool to validate (syntax check) SQL files.
Primarily for MySQL
Can be used in git pre-commit hooks to catch errors. Use it from your shell, offline and without any SQL server.
You can also use it to format SQL queries.
$ 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.
$ php-sqllint -r emacs tests/files/create-noname.sql tests/files/create-noname.sql:1.12:Error: The name of the entity was expected. tests/files/create-noname.sql:1.13:Error: A closing bracket was expected. tests/files/create-noname.sql:1.13:Error: At least one column definition was expected.
$ php-sqllint --format tests/files/select-unformatted.sql SELECT id, NAME, url FROM users WHERE DATE > NOW() AND id != 0 ORDER BY NAME LIMIT 10
ANSI colors are applied automatically when not piping; you can use the
--highlight option to override the automatism.
--highlight option values:
- No highlighting. Use it to disable automatic highlighting
- ANSI escape codes for your shell
- HTML tags
php-sqllint not detect a syntax error, or doesn't support a certain
Then please report a bug at phpmyadmin/sql-parser.
Install using composer
composer require cweiske/php-sqllint, the package is hosted on packagist
The download files are equipped with all dependencies. Just download and run.
See php-sqllint downloads page for all released versions.
$ composer install
Now you can use
./bin/php-sqllint without building the phar yourself.
- Write new version number into
Create the release
You'll need phing, the PHP build tool:
The result are
.phar files in
dist/ directory that you can execute:
$ ./dist/php-sqllint-0.0.1.phar tests/files/create-noname.sql Checking SQL syntax of tests/files/create-noname.sql Line 1, col 12 at "(": The name of the entity was expected.
php-sqllint is licensed under the AGPL v3 or later.
- Home page
- Source code