Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcocesarato/php-light-sql-parser
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.
https://github.com/marcocesarato/php-light-sql-parser
class database mysql parser php postrges sql sql-parser
Last synced: 2 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/marcocesarato/php-light-sql-parser
- Owner: marcocesarato
- License: gpl-3.0
- Created: 2018-05-29T12:53:19.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-16T13:21:09.000Z (about 2 years ago)
- Last Synced: 2024-11-13T13:57:08.904Z (2 months ago)
- Topics: class, database, mysql, parser, php, postrges, sql, sql-parser
- Language: PHP
- Homepage:
- Size: 54.7 KB
- Stars: 29
- Watchers: 2
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Light SQL Parser Class
**Version:** 0.2.105 beta
**Github:** https://github.com/marcocesarato/PHP-Light-SQL-Parser-Class
**Author:** Marco Cesarato
## 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
- php 4+
## Install
### Composer
1. Install composer
2. Type `composer require marcocesarato/sqlparser`
4. Enjoy## Usage
```php
$parser = new LightSQLParser("UPDATE Customers AS alias SET ContactName = 'Marco Cesarato', City = 'Milan' WHERE ID = 1;");
```OR
```php
$parser = new LightSQLParser();
$parser->setQuery("UPDATE Customers AS alias SET ContactName = 'Marco Cesarato', City = 'Milan' WHERE ID = 1;");
```### Method
How to retrieve the query's method:
```php
$parser->getMethod();
```
Output
```
string(6) "UPDATE"
```### Tables
How to retrieve the main the query's table:
```php
$parser->getTable();
```
Output
```
string(9) "Customers"
```How to retrieve the query's tables:
```php
$parser->getAllTables();
```
Output
```
array(1) {
[0]=>
string(9) "Customers"
}
```### Fields
How to retrieve the query's fields:
```php
$parser->getFields();
```
Output
```
array(2) {
[0]=>
string(11) "ContactName"
[1]=>
string(4) "City"
}
```## Methods
### LightSQLParser
| Method | Parameters | Description |
| ----------- | ----------------------------------- | -------------------------------------------------- |
| __construct | | Constructor |
| setQuery | | Set SQL Query string |
| getQuery | return array | Get SQL Query string |
| getAllQuery | return string | Get SQL All Query string |
| getMethod | param $query
return string | Get SQL Query method |
| getFields | param $query
return array | Get Query fields (at the moment only SELECTINSERTUPDATE) |
| getTable | param $query
return string | Get SQL Query First Table |
| getTables | return array | Get SQL Query Tables |
| getJoinTables | return array | Get SQL Query Join Tables |
| hasJoin | return bool | Return if has join tables |
| getSubQueries | return array | Get all SELECT subqueries |
| hasSubQueries | return bool | Return if has subqueries |