lib/SqlFormatter.php
public static function splitQuery($string)
    {
        $queries = array();
        $current_query = '';
        $empty = true;

        $tokens = self::tokenize($string);

        foreach ($tokens as $token) {
            // If this is a query separator
            if ($token[self::TOKEN_VALUE] === ';') {
                if (!$empty) {
                    $queries[] = $current_query.';';
                }
                $current_query = '';
                $empty = true;
                continue;
            }

            // If this is a non-empty character
            if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) {
                $empty = false;
            }

            $current_query .= $token[self::TOKEN_VALUE];
        }

        if (!$empty) {
            $queries[] = trim($current_query);
        }

        return $queries;
    }
public static function splitQuery($string)
    {
        $queries = array();
        $current_query = '';
        $empty = true;

        $tokens = self::tokenize($string);

        foreach ($tokens as $token) {
            // If this is a query separator
            if ($token[self::TOKEN_VALUE] === ';') {
                if (!$empty) {
                    $queries[] = $current_query.';';
                }
                $current_query = '';
                $empty = true;
                continue;
            }

            // If this is a non-empty character
            if ($token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_WHITESPACE && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_COMMENT && $token[self::TOKEN_TYPE] !== self::TOKEN_TYPE_BLOCK_COMMENT) {
                $empty = false;
            }

            $current_query .= $token[self::TOKEN_VALUE];
        }

        if (!$empty) {
            $queries[] = trim($current_query);
        }

        return $queries;
    }
public static function splitQuery ( $ string ) { $ queries = array ( ) ; $ current_query = '' ; $ empty = true ; $ tokens = self :: tokenize ( $ string ) ; foreach ( $ tokens as $ token ) { // If this is a query separator if ( $ token [ self :: TOKEN_VALUE ] === ';' ) { if ( ! $ empty ) { $ queries [ ] = $ current_query . ';' ; } $ current_query = '' ; $ empty = true ; continue ; } // If this is a non-empty character if ( $ token [ self :: TOKEN_TYPE ] !== self :: TOKEN_TYPE_WHITESPACE && $ token [ self :: TOKEN_TYPE ] !== self :: TOKEN_TYPE_COMMENT && $ token [ self :: TOKEN_TYPE ] !== self :: TOKEN_TYPE_BLOCK_COMMENT ) { $ empty = false ; } $ current_query .= $ token [ self :: TOKEN_VALUE ] ; } if ( ! $ empty ) { $ queries [ ] = trim ( $ current_query ) ; } return $ queries ; }
Split a SQL string into multiple queries.
Uses ";" as a query delimiter.

@param String $string The SQL string

@return Array An array of individual query strings without trailing semicolons
Split a SQL string into multiple queries . Uses ; as a query delimiter .