2017 © Pedro Peláez
 

library sql-parser

Easiest way to parse SQL

image

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

The README.md

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:

  1. Better documentation
  2. Fluent-Interface to generate SQL statements and alter the parsed content
  3. parse CREATE TABLE/ALTER TABLE (for SQLite, MySQL and PostgreSQL flavors)

The Versions

05/05 2017

dev-develop

dev-develop

Easiest way to parse SQL

  Sources   Download

MIT

The Development Requires

by Cesar Rodas

10/03 2016

dev-master

9999999-dev

Easiest way to parse SQL

  Sources   Download

MIT

The Development Requires

by Cesar Rodas

10/03 2016

v0.1.5

0.1.5.0

Easiest way to parse SQL

  Sources   Download

MIT

The Development Requires

by Cesar Rodas

10/03 2016

v0.1.4

0.1.4.0

Easiest way to parse SQL

  Sources   Download

MIT

The Development Requires

by Cesar Rodas

05/03 2016

v0.1.3

0.1.3.0

Easiest way to parse SQL

  Sources   Download

MIT

The Development Requires

by Cesar Rodas

29/02 2016

v0.1.2

0.1.2.0

Easiest way to parse SQL

  Sources   Download

MIT

The Development Requires

by Cesar Rodas

17/01 2016

v0.1.1

0.1.1.0

Easiest way to parse SQL

  Sources   Download

MIT

by Cesar Rodas

04/09 2015

v0.1.0

0.1.0.0

Easiest way to parse SQL

  Sources   Download

MIT

by Cesar Rodas