PHPackages                             doctrine/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. doctrine/sql-formatter

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

doctrine/sql-formatter
======================

a PHP SQL highlighting library

1.5.4(3mo ago)1.9k166.0M—7.9%27[9 issues](https://github.com/doctrine/sql-formatter/issues)[4 PRs](https://github.com/doctrine/sql-formatter/pulls)20MITHTMLPHP ^8.1CI passing

Since Apr 27Pushed 1mo ago6 watchersCompare

[ Source](https://github.com/doctrine/sql-formatter)[ Packagist](https://packagist.org/packages/doctrine/sql-formatter)[ Docs](https://github.com/doctrine/sql-formatter/)[ RSS](/packages/doctrine-sql-formatter/feed)WikiDiscussions 1.5.x Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (25)Used By (20)

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

[](#sqlformatter)

A lightweight php package for formatting sql statements.

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

History
-------

[](#history)

This package is a fork from Here is what the original History section says:

> 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.

― @jdorn

Usage
-----

[](#usage)

The `SqlFormatter` class has a method `format` which takes an SQL string as input and returns a formatted block.

Sample usage:

```
