doctrine/sql-formatter
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The Doctrine/SQL-Formatter is a PHP SQL highlighting library and a lightweight package used for formatting SQL statements. The tool effectively implements indentations, adds line breaks, and provides syntax highlighting for SQL statements, making long SQL codes more readable and easy to debug. This is especially advantageous for developers who frequently deal with auto-generated SQL statements.
The effective use of Doctrine/SQL-Formatter involves integrating it into your PHP script. First, ensure you have the package installed via composer. Initialize an instance of the SqlFormatter class, and use its methods like format
, highlight
, or compress
according to your needs.
For instance, to use the Doctrine/SQL-Formatter to format your SQL statement, you would do the following:
<?php
require_once 'vendor/autoload.php';
use Doctrine\SqlFormatter\SqlFormatter;
$query = "YOUR SQL QUERY HERE";
echo (new SqlFormatter())->format($query);
This will output the SQL query highlighted and formatted nicely.
However, if you only need syntax highlighting, you can use the highlight
method instead:
<?php
echo (new SqlFormatter())->highlight($query);
Or, for compressing the SQL command (removing comments and redundant whitespaces), use the compress
method:
echo (new SqlFormatter())->compress($query);
The Doctrine/SQL-Formatter docs can be found on the GitHub repository's README (https://github.com/doctrine/sql-formatter.git). The README provides comprehensive examples and detailed usage explanations to help you make the most out of this powerful library. It's advised to refer to this documentation to understand the full extent of its capabilities and for the latest updates or changes.