PHPackages                             marcocesarato/sqlparser - 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. marcocesarato/sqlparser

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

marcocesarato/sqlparser
=======================

 This class can parse SQL to get query type, tables, field values, etc.. It takes an string with a SQL statements and parses it to extract its different components. Currently the class can extract the SQL query method, the names of the tables involved in the query and the field values that are passed as parameters. This parser is pretty light respect phpsqlparser or others php sql parser.

0.2.106(5y ago)3143.0k↓35.4%14[1 issues](https://github.com/marcocesarato/PHP-Light-SQL-Parser-Class/issues)[1 PRs](https://github.com/marcocesarato/PHP-Light-SQL-Parser-Class/pulls)GPL-3.0-or-laterPHPPHP &gt;=4.0.0

Since Sep 11Pushed 3y ago1 watchersCompare

[ Source](https://github.com/marcocesarato/PHP-Light-SQL-Parser-Class)[ Packagist](https://packagist.org/packages/marcocesarato/sqlparser)[ RSS](/packages/marcocesarato-sqlparser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (4)Used By (0)

PHP Light SQL Parser Class
==========================

[](#php-light-sql-parser-class)

**Version:** 0.2.105 beta

**Github:**

**Author:** Marco Cesarato

Description
-----------

[](#description)

This class can parse SQL to get query type, tables, field values, etc..

It takes an string with a SQL statements and parses it to extract its different components.

Currently the class can extract the SQL query method, the names of the tables involved in the query and the field values that are passed as parameters. This parser is pretty light respect phpsqlparser or others php sql parser.

Requirements
------------

[](#requirements)

- php 4+

Install
-------

[](#install)

### Composer

[](#composer)

1. Install composer
2. Type `composer require marcocesarato/sqlparser`
3. Enjoy

Usage
-----

[](#usage)

```
$parser = new LightSQLParser("UPDATE Customers AS alias SET ContactName = 'Marco Cesarato', City = 'Milan' WHERE ID = 1;");
```

OR

```
$parser = new LightSQLParser();
$parser->setQuery("UPDATE Customers AS alias SET ContactName = 'Marco Cesarato', City = 'Milan' WHERE ID = 1;");
```

### Method

[](#method)

How to retrieve the query's method:

```
$parser->getMethod();
```

Output

```
string(6) "UPDATE"

```

### Tables

[](#tables)

How to retrieve the main the query's table:

```
$parser->getTable();
```

Output

```
string(9) "Customers"

```

How to retrieve the query's tables:

```
$parser->getAllTables();
```

Output

```
array(1) {
  [0]=>
  string(9) "Customers"
}

```

### Fields

[](#fields)

How to retrieve the query's fields:

```
$parser->getFields();
```

Output

```
array(2) {
  [0]=>
  string(11) "ContactName"
  [1]=>
  string(4) "City"
}

```

Methods
-------

[](#methods)

### LightSQLParser

[](#lightsqlparser)

MethodParametersDescription\_\_constructConstructorsetQuerySet SQL Query stringgetQueryreturn arrayGet SQL Query stringgetAllQueryreturn stringGet SQL All Query stringgetMethodparam $query
 return stringGet SQL Query methodgetFieldsparam $query
 return arrayGet Query fields (at the moment only SELECTINSERTUPDATE)getTableparam $query
 return stringGet SQL Query First TablegetTablesreturn arrayGet SQL Query TablesgetJoinTablesreturn arrayGet SQL Query Join TableshasJoinreturn boolReturn if has join tablesgetSubQueriesreturn arrayGet all SELECT subquerieshasSubQueriesreturn boolReturn if has subqueries

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99% of commits — single point of failure

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 ~253 days

Total

3

Last Release

1936d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/36447518?v=4)[Marco Cesarato](/maintainers/marcocesarato)[@marcocesarato](https://github.com/marcocesarato)

---

Top Contributors

[![marcocesarato](https://avatars.githubusercontent.com/u/36447518?v=4)](https://github.com/marcocesarato "marcocesarato (96 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (1 commits)")

---

Tags

classdatabasemysqlparserphppostrgessqlsql-parser

### Embed Badge

![Health badge](/badges/marcocesarato-sqlparser/health.svg)

```
[![Health](https://phpackages.com/badges/marcocesarato-sqlparser/health.svg)](https://phpackages.com/packages/marcocesarato-sqlparser)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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