SQL Formatter for PHP

Free online sql formatter with PHP code examples

Working with sql formatter in PHP? Our free online sql formatter helps PHP developers format, validate, and process data instantly. Below you will find PHP code examples using doctrine/sql-formatter / jdorn/sql-formatter so you can achieve the same result programmatically in your own projects.

Try the SQL Formatter Online

Use our free SQL Formatter directly in your browser — no setup required.

Open SQL Formatter

PHP Code Example

<?php
use Doctrine\SqlFormatter\SqlFormatter;

$sql = "SELECT u.name, u.email, o.total FROM users u JOIN orders o ON u.id = o.user_id WHERE o.total > 100 ORDER BY o.total DESC;";

$formatter = new SqlFormatter();
echo $formatter->format($sql);

Quick Setup

Library: doctrine/sql-formatter / jdorn/sql-formatter
composer require doctrine/sql-formatter

PHP Tips & Best Practices

  • doctrine/sql-formatter is the maintained fork
  • It supports syntax highlighting in CLI output
  • Use format() for formatted output, highlight() for colored output

Frequently Asked Questions

SQL Formatter in Other Languages

More PHP Tools