A lightweight php class for formatting sql statements. It can automatically indent and add line breaks in addition to syntax highlighting. I found myself having to debug auto-generated SQL statements all the time and wanted some way to easily output formatted HTML without having to include a huge library or copy and paste into online formatters. I was originally planning to extract the formatting code from PhpMyAdmin, but that was 10,000+ lines of code and used global variables. The SqlFormatter class has a static method 'format' which takes a SQL string as input and returns a formatted HTML block inside a pre tag. If you don't want syntax highlighting and only want the indentations and line breaks, pass in false as the second parameter. There is a separate method 'highlight' that preserves all original whitespace and just adds syntax highlighting.
Features
- A lightweight php class for formatting sql statements
- The compress method removes all comments and compresses whitespace
- If you want to keep all original whitespace formatting and just remove comments, you can use the removeComments method instead of compress
- Break up a SQL string into multiple queries
- The SqlFormatter class has a static method 'format' which takes a SQL string
- It can automatically indent and add line breaks in addition to syntax highlighting