jdorn/sql-formatter
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The jdorn/sql-formatter is a PHP SQL highlighting library. It is a highly efficient tool designed to format SQL statements. The package can auto-indent, add line breaks, and provide syntax highlighting to SQL strings. This is an invaluable tool for developers who find themselves constantly debugging auto-generated SQL statements and need a lightweight solution to produce easily readable, formatted HTML output.
Implementing the jdorn/sql-formatter in your code is a breeze. First, make sure to include the SqlFormatter.php in your PHP file.
The "format" method, which is a static method in the SqlFormatter class, takes in a SQL string as input and returns a formatted HTML block enclosed in a pre tag. Below is an example of how you can use it:
<?php
require_once('SqlFormatter.php');
$query = "SELECT count(*),`Column1`,`Testing`, `Testing Three` FROM `Table1`
WHERE Column1 = 'testing' AND ( (`Column2` = `Column3` OR Column4 >= NOW()) )
GROUP BY Column1 ORDER BY Column3 DESC LIMIT 5,10";
echo SqlFormatter::format($query);
If you only want to add indentations and line breaks without syntax highlighting, you can pass in false as the second parameter like so:
<?php
echo SqlFormatter::format($query, false);
Additionally, the 'highlight' method can be used if you only want syntax highlighting without changing the original whitespace. An example of its implementation is as follows:
<?php
echo SqlFormatter::highlight($query);
The library also comes with a 'compress' method to remove all comments and compress whitespace. This can be useful for creating queries that can be copy-pasted to the command line easily:
<?php
echo SqlFormatter::compress($query)
Finally, you can utilize the 'splitQuery' function to break up a SQL string into multiple queries:
<?php
$queries = SqlFormatter::splitQuery($sql);
You can find detailed documentation for the jdorn/sql-formatter on the project's GitHub page here. The readme file contains useful examples of the different ways you can utilize the SQL Formatter. Always make sure you're looking at the latest version of the readme file for the most accurate and up-to-date information.