PHP Classes
elePHPant
Icontem

Light PHP SQL Parser Class: Parse SQL to get query type, tables, field values

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-07-25 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 150 This week: 3All time: 8,582 This week: 144Up
Version License PHP version Categories
lightsqlparser 0.1.94Free for non-comm...5PHP 5, Databases, Parsers
Description Author

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 type (SELECT, INSERT, UPDATE, DELETE), the names of the tables involved in the query and the field values that are passed as parameters.

  Performance   Level  
Name: Marco Cesarato <contact>
Classes: 5 packages by
Country: Italy Italy
Age: 22
All time rank: 3099122 in Italy Italy
Week rank: 12 Up2 in Italy Italy Up
Innovation award
Innovation award
Nominee: 1x

Details

PHP Light SQL Parser Class

Version: 0.1.94 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+

Usage

$lsp = new LightSQLParser("UPDATE Customers as ae SET ContactName = 'Alfred Schmidt', City= 'Frankfurt' WHERE CustomerID = 1;");

OR

$lsp = new LightSQLParser();
$lsp->setQuery("UPDATE Customers as ae SET ContactName = 'Alfred Schmidt', City= 'Frankfurt' WHERE CustomerID = 1;");

Method

How retrieve query method:

$lsp->method();

Output

string(6) "UPDATE"

Tables

How retrieve query tables:

$lsp->tables();

Output

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

Fields

How retrieve query fields:

$lsp->fields();

Output

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

Methods

LightSQLParser

| Method | Parameters | Description | | ----------- | ----------------------------------- | -------------------------------------------------- | | __construct | | Constructor | | setQuery | | Set SQL Query string | | method | param $query<br> return string | Get SQL Query method | | fields | param $query<br> return array | Get Query fields (at the moment only SELECTINSERTUPDATE) | | table | param $query<br> return string | Get SQL Query First Table | | tables | return array | Get SQL Query Tables |

  Files folder image Files  
File Role Description
Accessible without login Plain text file demo.php Example Demo
Plain text file lightsqlparser.class.php Class Main Class
Accessible without login Plain text file README.md Doc. README

 Version Control Unique User Downloads Download Rankings  
 0%
Total:150
This week:3
All time:8,582
This week:144Up