library sql-parser
Easiest way to parse SQL
crodas/sql-parser
Easiest way to parse SQL
- Friday, May 5, 2017
- by crodas
- Repository
- 4 Watchers
- 9 Stars
- 1,116 Installations
- PHP
- 3 Dependents
- 0 Suggesters
- 2 Forks
- 2 Open issues
- 8 Versions
- 7 % Grown
SQLParser
SQL-Parser, (*1)
Why?
Sometimes we need to parse and validate SQL., (*2)
What does it do?
It parse SQL (mostly MySQL's SQL) and exposes the SQL query as an object so it can be manipulated and assembled back to a query., (*3)
How to install?
composer install crodas/sql-parser
How to use it?
require __DIR__ . "/vendor/autoload.php";
$parser = new SQLParser;
$queries = $parser->parse("SELECT * FROM table1 WHERE id = :id");
var_dump(get_class($queries[0])); // string(16) "SQLParser\Select"
var_dump($queries[0]->getTable()[0]->getValue()); // string(6) "table1"
/*
array(1) {
[0] =>
string(2) "id"
}
*/
var_dump($queries[0]->getVariables());
// SELECT * FROM 'table1' WHERE 'id' = :id
echo $queries[0] . "\n";
SQLParser\Writer\SQL::setInstance(new SQLParser\Writer\MySQL);
// SELECT * FROM `table1` WHERE `id` = :id
echo $queries[0] . "\n";
TODO:
- Better documentation
- Fluent-Interface to generate SQL statements and alter the parsed content
- parse CREATE TABLE/ALTER TABLE (for SQLite, MySQL and PostgreSQL flavors)
dev-develop
dev-develop
Easiest way to parse SQL
Sources
Download
MIT
The Development Requires
by
Cesar Rodas
dev-master
9999999-dev
Easiest way to parse SQL
Sources
Download
MIT
The Development Requires
by
Cesar Rodas
v0.1.5
0.1.5.0
Easiest way to parse SQL
Sources
Download
MIT
The Development Requires
by
Cesar Rodas
v0.1.4
0.1.4.0
Easiest way to parse SQL
Sources
Download
MIT
The Development Requires
by
Cesar Rodas
v0.1.3
0.1.3.0
Easiest way to parse SQL
Sources
Download
MIT
The Development Requires
by
Cesar Rodas
v0.1.2
0.1.2.0
Easiest way to parse SQL
Sources
Download
MIT
The Development Requires
by
Cesar Rodas
v0.1.1
0.1.1.0
Easiest way to parse SQL
Sources
Download
MIT
by
Cesar Rodas
v0.1.0
0.1.0.0
Easiest way to parse SQL
Sources
Download
MIT
by
Cesar Rodas