public static function getAll($query)
    {
        $parser = new Parser($query);

        if (empty($parser->statements[0])) {
            return static::getFlags(null, true);
        }

        $statement = $parser->statements[0];

        $ret = static::getFlags($statement, true);

        $ret['parser'] = $parser;
        $ret['statement'] = $statement;

        if ($statement instanceof SelectStatement) {
            $ret['select_tables'] = [];
            $ret['select_expr'] = [];

            // Finding tables' aliases and their associated real names.
            $tableAliases = [];
            foreach ($statement->from as $expr) {
                if (isset($expr->table, $expr->alias) && ($expr->table !== '') && ($expr->alias !== '')
                ) {
                    $tableAliases[$expr->alias] = [
                        $expr->table,
                        isset($expr->database) ? $expr->database : null,
                    ];
                }
            }

            // Trying to find selected tables only from the select expression.
            // Sometimes, this is not possible because the tables aren't defined
            // explicitly (e.g. SELECT * FROM film, SELECT film_id FROM film).
            foreach ($statement->expr as $expr) {
                if (isset($expr->table) && ($expr->table !== '')) {
                    if (isset($tableAliases[$expr->table])) {
                        $arr = $tableAliases[$expr->table];
                    } else {
                        $arr = [
                            $expr->table,
                            (isset($expr->database) && ($expr->database !== '')) ?
                                $expr->database : null,
                        ];
                    }
                    if (! in_array($arr, $ret['select_tables'])) {
                        $ret['select_tables'][] = $arr;
                    }
                } else {
                    $ret['select_expr'][] = $expr->expr;
                }
            }

            // If no tables names were found in the SELECT clause or if there
            // are expressions like * or COUNT(*), etc. tables names should be
            // extracted from the FROM clause.
            if (empty($ret['select_tables'])) {
                foreach ($statement->from as $expr) {
                    if (isset($expr->table) && ($expr->table !== '')) {
                        $arr = [
                            $expr->table,
                            (isset($expr->database) && ($expr->database !== '')) ?
                                $expr->database : null,
                        ];
                        if (! in_array($arr, $ret['select_tables'])) {
                            $ret['select_tables'][] = $arr;
                        }
                    }
                }
            }
        }

        return $ret;
    }
public static function getAll($query)
    {
        $parser = new Parser($query);

        if (empty($parser->statements[0])) {
            return static::getFlags(null, true);
        }

        $statement = $parser->statements[0];

        $ret = static::getFlags($statement, true);

        $ret['parser'] = $parser;
        $ret['statement'] = $statement;

        if ($statement instanceof SelectStatement) {
            $ret['select_tables'] = [];
            $ret['select_expr'] = [];

            // Finding tables' aliases and their associated real names.
            $tableAliases = [];
            foreach ($statement->from as $expr) {
                if (isset($expr->table, $expr->alias) && ($expr->table !== '') && ($expr->alias !== '')
                ) {
                    $tableAliases[$expr->alias] = [
                        $expr->table,
                        isset($expr->database) ? $expr->database : null,
                    ];
                }
            }

            // Trying to find selected tables only from the select expression.
            // Sometimes, this is not possible because the tables aren't defined
            // explicitly (e.g. SELECT * FROM film, SELECT film_id FROM film).
            foreach ($statement->expr as $expr) {
                if (isset($expr->table) && ($expr->table !== '')) {
                    if (isset($tableAliases[$expr->table])) {
                        $arr = $tableAliases[$expr->table];
                    } else {
                        $arr = [
                            $expr->table,
                            (isset($expr->database) && ($expr->database !== '')) ?
                                $expr->database : null,
                        ];
                    }
                    if (! in_array($arr, $ret['select_tables'])) {
                        $ret['select_tables'][] = $arr;
                    }
                } else {
                    $ret['select_expr'][] = $expr->expr;
                }
            }

            // If no tables names were found in the SELECT clause or if there
            // are expressions like * or COUNT(*), etc. tables names should be
            // extracted from the FROM clause.
            if (empty($ret['select_tables'])) {
                foreach ($statement->from as $expr) {
                    if (isset($expr->table) && ($expr->table !== '')) {
                        $arr = [
                            $expr->table,
                            (isset($expr->database) && ($expr->database !== '')) ?
                                $expr->database : null,
                        ];
                        if (! in_array($arr, $ret['select_tables'])) {
                            $ret['select_tables'][] = $arr;
                        }
                    }
                }
            }
        }

        return $ret;
    }
public static function getAll ( $ query ) { $ parser = new Parser ( $ query ) ; if ( empty ( $ parser -> statements [ 0 ] ) ) { return static :: getFlags ( null , true ) ; } $ statement = $ parser -> statements [ 0 ] ; $ ret = static :: getFlags ( $ statement , true ) ; $ ret [ 'parser' ] = $ parser ; $ ret [ 'statement' ] = $ statement ; if ( $ statement instanceof SelectStatement ) { $ ret [ 'select_tables' ] = [ ] ; $ ret [ 'select_expr' ] = [ ] ; // Finding tables' aliases and their associated real names. $ tableAliases = [ ] ; foreach ( $ statement -> from as $ expr ) { if ( isset ( $ expr -> table , $ expr -> alias ) && ( $ expr -> table !== '' ) && ( $ expr -> alias !== '' ) ) { $ tableAliases [ $ expr -> alias ] = [ $ expr -> table , isset ( $ expr -> database ) ? $ expr -> database : null , ] ; } } // Trying to find selected tables only from the select expression. // Sometimes, this is not possible because the tables aren't defined // explicitly (e.g. SELECT * FROM film, SELECT film_id FROM film). foreach ( $ statement -> expr as $ expr ) { if ( isset ( $ expr -> table ) && ( $ expr -> table !== '' ) ) { if ( isset ( $ tableAliases [ $ expr -> table ] ) ) { $ arr = $ tableAliases [ $ expr -> table ] ; } else { $ arr = [ $ expr -> table , ( isset ( $ expr -> database ) && ( $ expr -> database !== '' ) ) ? $ expr -> database : null , ] ; } if ( ! in_array ( $ arr , $ ret [ 'select_tables' ] ) ) { $ ret [ 'select_tables' ] [ ] = $ arr ; } } else { $ ret [ 'select_expr' ] [ ] = $ expr -> expr ; } } // If no tables names were found in the SELECT clause or if there // are expressions like * or COUNT(*), etc. tables names should be // extracted from the FROM clause. if ( empty ( $ ret [ 'select_tables' ] ) ) { foreach ( $ statement -> from as $ expr ) { if ( isset ( $ expr -> table ) && ( $ expr -> table !== '' ) ) { $ arr = [ $ expr -> table , ( isset ( $ expr -> database ) && ( $ expr -> database !== '' ) ) ? $ expr -> database : null , ] ; if ( ! in_array ( $ arr , $ ret [ 'select_tables' ] ) ) { $ ret [ 'select_tables' ] [ ] = $ arr ; } } } } } return $ ret ; }
Parses a query and gets all information about it.

@param string $query the query to be parsed

@return array The array returned is the one returned by
`static::getFlags()`, with the following keys added:
- parser - the parser used to analyze the query;
- statement - the first statement resulted from parsing;
- select_tables - the real name of the tables selected;
if there are no table names in the `SELECT`
expressions, the table names are fetched from the
`FROM` expressions
- select_expr - selected expressions
Parses a query and gets all information about it .