Format SQL statements with SqlFormatter
1.5.xThe SqlFormatter class provides a format method that takes an SQL string and returns a formatted block with automatic indentation, line breaks, and syntax highlighting. By default, when running in a CLI environment, it uses CliHighlighter. You can also pass specific Highlighter implementations (like HtmlHighlighter) to the constructor to change the highlighting output.
<?php
require_once 'vendor/autoload.php';
use Doctrine\
SqlFormatter\\SqlFormatter;
$query = "SELECT count(*),`Column1`,`Testing`, `Testing Three` FROM `Table1`\n WHERE Column1 = 'testing' AND ( (`Column2` = `Column3` OR Column4 >= NOW()) )\n GROUP BY Column1 ORDER BY Column3 DESC LIMIT 5,10";
echo (new SqlFormatter())->format($query);