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)3145.9k↓34.3%14[4 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 3d 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 72% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity46

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

1983d 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

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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