A lightweight php class for formatting sql statements. It can automatically indent and add line breaks in addition to syntax highlighting. 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. 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. If you don't want syntax highlighting and only want the indentations and line breaks, pass in false as the second parameter. There is a separate method 'highlight' that preserves all original whitespace and just adds syntax highlighting.

Features

  • A lightweight php class for formatting sql statements
  • The compress method removes all comments and compresses whitespace
  • If you want to keep all original whitespace formatting and just remove comments, you can use the removeComments method instead of compress
  • Break up a SQL string into multiple queries
  • The SqlFormatter class has a static method 'format' which takes a SQL string
  • It can automatically indent and add line breaks in addition to syntax highlighting

Project Samples

Project Activity

See All Activity >

Categories

Data Formats

License

MIT License

Follow SqlFormatter

SqlFormatter Web Site

You Might Also Like
The #1 Embedded Analytics Solution for SaaS Teams. Icon
The #1 Embedded Analytics Solution for SaaS Teams.

Qrvey saves engineering teams time and money with a turnkey multi-tenant solution connecting your data warehouse to your SaaS application.

Qrvey’s comprehensive embedded analytics software enables you to design more customizable analytics experiences for your end users.
Try Developer Playground
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of SqlFormatter!

Additional Project Details

Programming Language

PHP

Related Categories

PHP Data Formats Software

Registered

2022-02-09