* Support php 5.3 for sql parser lib.
This commit is contained in:
+10
-15
@@ -4,15 +4,13 @@ A validating SQL lexer and parser with a focus on MySQL dialect.
|
||||
|
||||
## Code status
|
||||
|
||||

|
||||

|
||||
[](https://scrutinizer-ci.com/g/phpmyadmin/sql-parser/?branch=master)
|
||||
[](https://codecov.io/github/phpmyadmin/sql-parser?branch=master)
|
||||
[](https://codecov.io/github/phpmyadmin/sql-parser?branch=QA)
|
||||
[](https://scrutinizer-ci.com/g/phpmyadmin/sql-parser/?branch=master)
|
||||
[](https://hosted.weblate.org/engage/phpmyadmin/?utm_source=widget)
|
||||
[](https://packagist.org/packages/phpmyadmin/sql-parser)
|
||||
[](https://www.codetriage.com/phpmyadmin/sql-parser)
|
||||
[](https://shepherd.dev/github/phpmyadmin/sql-parser)
|
||||
[](https://infection.github.io)
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -59,7 +57,7 @@ cat example.sql | ./vendor/bin/lint-query
|
||||
### Formatting SQL query
|
||||
|
||||
```php
|
||||
echo PhpMyAdmin\SqlParser\Utils\Formatter::format($query, ['type' => 'html']);
|
||||
echo PhpMyAdmin\SqlParser\Utils\Formatter::format($query, array('type' => 'html'));
|
||||
```
|
||||
|
||||
### Discoverying query type
|
||||
@@ -80,53 +78,50 @@ echo $flags['querytype'];
|
||||
```php
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
$query1 = 'select * from a';
|
||||
$query1 = "select * from a";
|
||||
$parser = new PhpMyAdmin\SqlParser\Parser($query1);
|
||||
|
||||
// inspect query
|
||||
var_dump($parser->statements[0]); // outputs object(PhpMyAdmin\SqlParser\Statements\SelectStatement)
|
||||
|
||||
// modify query by replacing table a with table b
|
||||
$table2 = new \PhpMyAdmin\SqlParser\Components\Expression('', 'b', '', '');
|
||||
$table2 = new \PhpMyAdmin\SqlParser\Components\Expression("", "b", "", "");
|
||||
$parser->statements[0]->from[0] = $table2;
|
||||
|
||||
// build query again from an array of object(PhpMyAdmin\SqlParser\Statements\SelectStatement) to a string
|
||||
$statement = $parser->statements[0];
|
||||
$query2 = $statement->build();
|
||||
var_dump($query2); // outputs string(19) 'SELECT * FROM `b` '
|
||||
var_dump($query2); // outputs string(19) "SELECT * FROM `b` "
|
||||
|
||||
// Change SQL mode
|
||||
PhpMyAdmin\SqlParser\Context::setMode('ANSI_QUOTES');
|
||||
|
||||
// build the query again using different quotes
|
||||
$query2 = $statement->build();
|
||||
var_dump($query2); // outputs string(19) 'SELECT * FROM "b" '
|
||||
var_dump($query2); // outputs string(19) "SELECT * FROM "b" "
|
||||
```
|
||||
|
||||
## Localization
|
||||
|
||||
You can localize error messages installing `phpmyadmin/motranslator` version `5.0` or newer:
|
||||
|
||||
You can localize error messages installing `phpmyadmin/motranslator` version `4.0` or newer:
|
||||
```sh
|
||||
composer require phpmyadmin/motranslator:^5.0
|
||||
composer require phpmyadmin/motranslator:^4.0
|
||||
```
|
||||
|
||||
The locale is automatically detected from your environment, you can also set a different locale
|
||||
|
||||
**From cli**:
|
||||
|
||||
```sh
|
||||
LC_ALL=pl ./vendor/bin/lint-query --query "SELECT 1"
|
||||
```
|
||||
|
||||
**From php**:
|
||||
|
||||
```php
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
$GLOBALS['lang'] = 'pl';
|
||||
|
||||
$query1 = 'select * from a';
|
||||
$query1 = "select * from a";
|
||||
$parser = new PhpMyAdmin\SqlParser\Parser($query1);
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user