PHPackages                             maximilian-kresse/sql-formatter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. maximilian-kresse/sql-formatter

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

maximilian-kresse/sql-formatter
===============================

a PHP SQL highlighting library fork of jdorn/sql-formatter

v1.2.18(7y ago)1980MITHTMLPHP &gt;=5.2.4

Since Oct 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/MaximilianKresse/sql-formatter)[ Packagist](https://packagist.org/packages/maximilian-kresse/sql-formatter)[ Docs](https://github.com/MaximilianKresse/sql-formatter/)[ RSS](/packages/maximilian-kresse-sql-formatter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (9)Used By (0)

SqlFormatter
============

[](#sqlformatter)

A lightweight php class for formatting sql statements.

It can automatically indent and add line breaks in addition to syntax highlighting.

History
=======

[](#history)

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.

I saw that other people had the same problem and used Stack Overflow user losif's answer as a starting point.

Usage
=====

[](#usage)

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.

Sample usage:

```
