Download the PHP package pinahq/sql-parser without Composer

On this page you can find all versions of the php package pinahq/sql-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sql-parser

SQLParser - Parse MySQL schemas in PHP, fast

Build Status Coverage Status

This library takes MySQL CREATE TABLE statements and returns a data structure representing the table that it defines. MySQL syntax version 5.7 is supported. This library does not try to validate input - the goal is to deconstruct valid CREATE TABLE statements.

Installation

You can install this package using composer. To add it to your composer.json:

composer require iamcal/sql-parser

You can then load it using the composer autoloader:

require_once 'vendor/autoload.php';
use iamcal\SQLParser;

$parser = new SQLParser();

If you don't use composer, you can skip the autoloader and include src/SQLParser.php directly.

Usage

To extract the tables defined in SQL:

$parser = new SQLParser();
$parser->parse($sql);

print_r($parser->tables);

The tables property is an array of tables, each of which is a nested array structure defining the table's structure:

CREATE TABLE `achievements_counts` (
  `achievement_id` int(10) unsigned NOT NULL,
  `num_players` int(10) unsigned NOT NULL,
  `date_updated` int(10) unsigned NOT NULL,
  PRIMARY KEY (`achievement_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

[
    'achievements_counts' => [
        'name' => 'achievements_counts',
        'fields' => [
            [
                'name' => 'achievement_id',
                'type' => 'INT',
                'length' => '10',
                'unsigned' => true,
                'null' => false,
            ],
            [
                'name' => 'num_players',
                'type' => 'INT',
                'length' => '10',
                'unsigned' => true,
                'null' => false,
            ],
            [
                'name' => 'date_updated',
                'type' => 'INT',
                'length' => '10',
                'unsigned' => true,
                'null' => false,
            ],
        ],
        'indexes' => [
            [
                'type' => 'PRIMARY',
                'cols' => [
                    [
                        'name' => 'achievement_id',
                    ],
                ],
            ],
        ],
        'props' => [
            'ENGINE' => 'InnoDB',
            'CHARSET' => 'utf8',
        ],
    ],
]

You can also use the lexer directly to work with other piece of SQL:

$parser = new SQLParser();
$parser->lex($sql);

print($parser->tokens);

The tokens property contains an array of tokens. SQL keywords are returned as uppercase, with multi-word terms (e.g. DEFAULT CHARACTER SET) as a single token. Strings and escaped identifiers are not further processed; they are returned exactly as expressed in the input SQL.

Performance

My test target is an 88K SQL file containing 114 tables from Glitch's main database.

The first version, using php-sql-parser, took over 60 seconds just to lex the input. This was obviously not a great option.

The current implementation uses a hand-written lexer which takes around 140ms to lex the same input and imposes less odd restrictions. This seems to be the way to go.

History

This library was created to parse multiple CREATE TABLE schemas and compare them, so figure out what needs to be done to migrate one to the other.

This is based on the system used at b3ta, Flickr and then Tiny Speck to check the differences between production and development databases and between shard instances. The original system just showed a diff (see SchemaDiff), but that was a bit of a pain.

Unsupported features

MySQL table definitions have a lot of options, so some things just aren't supported. They include:

If you need support for one of these features, open an issue or (better) send a pull request with tests.


All versions of sql-parser with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pinahq/sql-parser contains the following files

Loading the files please wait ....