PHPackages                             jtfnetoo/sql-parser - 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. jtfnetoo/sql-parser

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

jtfnetoo/sql-parser
===================

Fork of phpmyadmin https://github.com/phpmyadmin/sql-parser.

v4.1.6(9y ago)018GPL-2.0+PHPPHP &gt;=5.3.0

Since Aug 20Pushed 9y ago1 watchersCompare

[ Source](https://github.com/JoseNetoooo/sql-parser)[ Packagist](https://packagist.org/packages/jtfnetoo/sql-parser)[ Docs](https://github.com/JoseNetoooo/sql-parser)[ RSS](/packages/jtfnetoo-sql-parser/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (2)Versions (51)Used By (0)

SQL Parser
==========

[](#sql-parser)

A validating SQL lexer and parser with a focus on MySQL dialect.

Code status
-----------

[](#code-status)

[![Build Status](https://camo.githubusercontent.com/f8ef749dc584c1d7307c674ac76378a6babcce88d7db00d170e5cff4ea154631/68747470733a2f2f7472617669732d63692e6f72672f7068706d7961646d696e2f73716c2d7061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpmyadmin/sql-parser)[![Code Coverage](https://camo.githubusercontent.com/e1571626964674a2b42dc6fcd48d13bdfa1ec4ea7188785f4272b2af2a143383/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068706d7961646d696e2f73716c2d7061727365722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phpmyadmin/sql-parser/?branch=master)[![codecov.io](https://camo.githubusercontent.com/b749697473d31bb56605277e78811160aca2ffd60850888abbcc437b18018672/68747470733a2f2f636f6465636f762e696f2f6769746875622f7068706d7961646d696e2f73716c2d7061727365722f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/phpmyadmin/sql-parser?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/430849b3942f80d12afcacc31880fecec999a16a52e1a72deaac28dd4c4fdf8b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068706d7961646d696e2f73716c2d7061727365722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phpmyadmin/sql-parser/?branch=master)[![Translation status](https://camo.githubusercontent.com/ad8ae706f3a0e629cfaef93efa631809ae588e16019cd2de8c29e4a53ef80da6/68747470733a2f2f686f737465642e7765626c6174652e6f72672f776964676574732f7068706d7961646d696e2f2d2f7376672d62616467652e737667)](https://hosted.weblate.org/engage/phpmyadmin/?utm_source=widget)

Installation
------------

[](#installation)

Please use [Composer](https://getcomposer.org/) to install:

```
composer require phpmyadmin/sql-parser

```

Documentation
-------------

[](#documentation)

The API documentation is available at .

Usage
-----

[](#usage)

### Command line utilities

[](#command-line-utilities)

Command line utility to syntax highlight SQL query:

```
./vendor/bin/highlight-query --query "SELECT 1"
```

Command line utility to lint SQL query:

```
./vendor/bin/lint-query --query "SELECT 1"
```

Command line utility to tokenize SQL query:

```
./vendor/bin/tokenize-query --query "SELECT 1"
```

### Formatting SQL query

[](#formatting-sql-query)

```
echo PhpMyAdmin\SqlParser\Utils\Formatter::format($query, array('type' => 'html'));
```

### Discoverying query type

[](#discoverying-query-type)

```
use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Utils\Query;

$query = 'OPTIMIZE TABLE tbl';
$parser = new Parser($query);
$flags = Query::getFlags($parser->statements[0]);

echo $flags['querytype'];
```

### Parsing and building SQL query

[](#parsing-and-building-sql-query)

```
require __DIR__."/vendor/autoload.php";

$query1 = "select * from a";
$parser = new PhpMyAdmin\SqlParser\Parser($query1);

// inspect query
var_dump($parser->statements[0]); // outputs object(PhpMyAdmin\SqlParser\Statements\SelectStatement)

// modify query by replacing table a with table b
$table2 = new \PhpMyAdmin\SqlParser\Components\Expression("", "b", "", "");
$parser->statements[0]->from[0] = $table2;

// build query again from an array of object(PhpMyAdmin\SqlParser\Statements\SelectStatement) to a string
$statement = $parser->statements[0];
$query2 = $statement->build();
var_dump($query2); // outputs string(19) "SELECT  * FROM `b` "

// Change SQL mode
PhpMyAdmin\SqlParser\Context::setMode('ANSI_QUOTES');

// build the query again using different quotes
$query2 = $statement->build();
var_dump($query2); // outputs string(19) "SELECT  * FROM "b" "
```

Localization
------------

[](#localization)

You can localize error messages installing `phpmyadmin/motranslator` version `3.0` or newer:

```
composer require phpmyadmin/motranslator:^3.0
```

The locale is automatically detected from your enrivonment, you can also set a different locale

**From cli**:

```
LC_ALL=pl ./vendor/bin/lint-query --query "SELECT 1"
```

**From php**:

```
require __DIR__."/vendor/autoload.php";

$GLOBALS['lang'] = 'pl';

$query1 = "select * from a";
$parser = new PhpMyAdmin\SqlParser\Parser($query1);
```

More information
----------------

[](#more-information)

This library was originally created during the Google Summer of Code 2015 and has been used by phpMyAdmin since version 4.5.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Recently: every ~25 days

Total

49

Last Release

3318d ago

Major Versions

v1.0.0 → v2.0.02015-09-25

v2.1.3 → v3.0.02015-10-03

v3.4.17 → v4.0.02017-01-23

PHP version history (3 changes)v1.0.0PHP &gt;=5.3.0

v3.0.8PHP &gt;=5.5.0

v3.1.0PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/df82c2179119fca787f39ac6c3921a36b26f351f545eb3cda3e2627bce83f668?d=identicon)[jtfnetoo](/maintainers/jtfnetoo)

---

Top Contributors

[![nijel](https://avatars.githubusercontent.com/u/212189?v=4)](https://github.com/nijel "nijel (344 commits)")[![udan11](https://avatars.githubusercontent.com/u/4147664?v=4)](https://github.com/udan11 "udan11 (216 commits)")[![devenbansod](https://avatars.githubusercontent.com/u/5762808?v=4)](https://github.com/devenbansod "devenbansod (76 commits)")[![bigfoot90](https://avatars.githubusercontent.com/u/4598274?v=4)](https://github.com/bigfoot90 "bigfoot90 (40 commits)")[![weblate](https://avatars.githubusercontent.com/u/1607653?v=4)](https://github.com/weblate "weblate (8 commits)")[![madhuracj](https://avatars.githubusercontent.com/u/1410004?v=4)](https://github.com/madhuracj "madhuracj (7 commits)")[![007durgesh219](https://avatars.githubusercontent.com/u/7701929?v=4)](https://github.com/007durgesh219 "007durgesh219 (4 commits)")[![JoseNetoooo](https://avatars.githubusercontent.com/u/1051129?v=4)](https://github.com/JoseNetoooo "JoseNetoooo (3 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (3 commits)")[![dingo1313](https://avatars.githubusercontent.com/u/31185797?v=4)](https://github.com/dingo1313 "dingo1313 (3 commits)")[![fujisoft](https://avatars.githubusercontent.com/u/24379283?v=4)](https://github.com/fujisoft "fujisoft (3 commits)")[![ncwgf](https://avatars.githubusercontent.com/u/17694385?v=4)](https://github.com/ncwgf "ncwgf (3 commits)")[![panos78](https://avatars.githubusercontent.com/u/3087817?v=4)](https://github.com/panos78 "panos78 (2 commits)")[![skecskes](https://avatars.githubusercontent.com/u/3411329?v=4)](https://github.com/skecskes "skecskes (2 commits)")[![touchiep](https://avatars.githubusercontent.com/u/16538345?v=4)](https://github.com/touchiep "touchiep (2 commits)")[![victorenator](https://avatars.githubusercontent.com/u/988209?v=4)](https://github.com/victorenator "victorenator (2 commits)")[![gr2442](https://avatars.githubusercontent.com/u/8940148?v=4)](https://github.com/gr2442 "gr2442 (1 commits)")[![bhargavisabbisetty](https://avatars.githubusercontent.com/u/24894514?v=4)](https://github.com/bhargavisabbisetty "bhargavisabbisetty (1 commits)")[![fezfez](https://avatars.githubusercontent.com/u/1162307?v=4)](https://github.com/fezfez "fezfez (1 commits)")[![elrossco22](https://avatars.githubusercontent.com/u/16711585?v=4)](https://github.com/elrossco22 "elrossco22 (1 commits)")

---

Tags

parsersqllexeranalysis

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jtfnetoo-sql-parser/health.svg)

```
[![Health](https://phpackages.com/badges/jtfnetoo-sql-parser/health.svg)](https://phpackages.com/packages/jtfnetoo-sql-parser)
```

###  Alternatives

[phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

48252.2M72](/packages/phpmyadmin-sql-parser)[greenlion/php-sql-parser

A pure PHP SQL (non validating) parser w/ focus on MySQL dialect of SQL

64112.4M97](/packages/greenlion-php-sql-parser)[timgws/query-builder-parser

Build complex Eloquent &amp; QueryBuilder queries automatically when using jQuery-QueryBuilder

161403.9k](/packages/timgws-query-builder-parser)[sad_spirit/pg_builder

Query builder for Postgres backed by SQL parser

5940.0k1](/packages/sad-spirit-pg-builder)[nilportugues/sql-query-formatter

A very lightweight PHP class that reformats unreadable and computer-generated SQL query statements to human-friendly, readable text.

391.2M29](/packages/nilportugues-sql-query-formatter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
