| Recommend this page to a friend! |
| Info | Example | Reputation | Support forum | Blog | Links |
| Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
| 2025-07-28 (6 months ago) | Not enough user ratings | Total: 242 | All time: 8,023 This week: 38 | |||||
| Version | License | PHP version | Categories | |||
| lightsqlparser 0.1.97 | Free for non-comm... | 5 | PHP 5, Databases, Parsers |
| Collaborate with this project | Author | |
PHP-Light-SQL-Parser - github.com Description This class can parse SQL to get query type, tables, field values, etc.. |
<?php
|
Version: 0.2.105 beta
Github: https://github.com/marcocesarato/PHP-Light-SQL-Parser-Class
Author: Marco Cesarato
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.
$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;");
How to retrieve the query's method:
$parser->getMethod();
Output
string(6) "UPDATE"
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"
}
How to retrieve the query's fields:
$parser->getFields();
Output
array(2) {
[0]=>
string(11) "ContactName"
[1]=>
string(4) "City"
}
| 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<br> return string | Get SQL Query method | | getFields | param $query<br> return array | Get Query fields (at the moment only SELECTINSERTUPDATE) | | getTable | param $query<br> 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 |
| File | Role | Description | ||
|---|---|---|---|---|
| Data | Auxiliary data | |||
| Example | Demo | |||
| Lic. | License text | |||
| Class | Main Class | |||
| Doc. | README | |||
| Data | Auxiliary data | |||
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
| Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
| 75% |
|
|
| User Comments (1) | |||||
| |||||
| Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.