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 pas
Requires
- php: >=4.0.0
This package is auto-updated.
Last update: 2024-11-11 21:12:03 UTC
README
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
- Install composer
- Type
composer require marcocesarato/sqlparser
- Enjoy
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
How to retrieve the query's method:
$parser->getMethod();
Output
string(6) "UPDATE"
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
How to retrieve the query's fields:
$parser->getFields();
Output
array(2) {
[0]=>
string(11) "ContactName"
[1]=>
string(4) "City"
}