[phpMyAdmin Developers] get the table name from sql query

Manish Bisht manish.bisht490 at gmail.com
Wed Aug 2 16:48:45 CEST 2017


Thanks,

One more thing for the import page (import.php) does the query on
import page are shown as soon as they are executed using ajax or all
the import queries are executed first and then shown on the page.

Also what is the use of this link `$response->addJSON('ajax_reload',
$ajax_reload);` in import.php file
Manish Bisht
Email : hi at manishbisht.me
Website : https://manishbisht.me



On Wed, Aug 2, 2017 at 5:21 PM, Michal Čihař <michal at cihar.com> wrote:
> Hi
>
> Manish Bisht píše v St 02. 08. 2017 v 16:48 +0530:
>> I have one create sql query in one variable.
>>
>> Is there any way I can get the table name from the sql query using
>> sql
>> parser or any other other way.
>
> Yes, SQL parser can do that:
>
> <?php
>
> require 'vendor/autoload.php';
>
> use PhpMyAdmin\SqlParser\Parser;
> use PhpMyAdmin\SqlParser\Utils\Query;
> use PhpMyAdmin\SqlParser\Statements\CreateStatement;
>
> $query = 'CREATE TABLE t (c CHAR(20) CHARACTER SET utf8 COLLATE
> utf8_bin)';
>
> $parser = new Parser($query);
> $statement = $parser->statements[0];
> foreach ($parser->statements as $statement) {
>     if ($statement instanceof CreateStatement) {
>         echo "Creating table $statement->name\n";
>     }
> }
>
>>
>> I am thinking of splitting the query by single space and then using
>> the 3 value of the array as the table name.
>
> No, please do not make any assumptions on the SQL query structure, this
> is very easy to break:
>
> CRATE TABLE `table with spaces` ...
>
> CREATE TABLE IF NOT EXIST `table` ...
>
> CREATE TABLE /* comment */ `table` ...
>
> --
>         Michal Čihař | https://cihar.com/ | https://weblate.org/
>
> _______________________________________________
> Developers mailing list
> Developers at phpmyadmin.net
> https://lists.phpmyadmin.net/mailman/listinfo/developers
>



More information about the Developers mailing list