Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on May 16, 2024 via composer

jdorn/sql-formatter v1.2.17

a PHP SQL highlighting library
Package summary
Share
0
issues
1
license
1
MIT
Package created
13 Sep 2012
Version published
12 Jan 2014
Maintainers
1
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
jdorn/sql-formatter@v1.2.17
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of jdorn/sql-formatter 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does jdorn/sql-formatter do?

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.

How do you use jdorn/sql-formatter?

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);

Where are the jdorn/sql-formatter docs?

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.