PHP code example of nextras / multi-query-parser

1. Go to this page and download the library: Download nextras/multi-query-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nextras / multi-query-parser example snippets


use Nextras\MultiQueryParser\MySqlMultiQueryParser;

$parser = new MySqlMultiQueryParser();

foreach ($parser->parseFile('migrations.sql') as $query) {
    $connection->query($query);
}

$sql = "CREATE TABLE users (id INT); INSERT INTO users VALUES (1);";

foreach ($parser->parseString($sql) as $query) {
    $connection->query($query);
}

$stream = fopen('migrations.sql', 'r');

foreach ($parser->parseFileStream($stream) as $query) {
    $connection->query($query);
}

use Nextras\MultiQueryParser\Strategy\PrependLeadingComments;

$parser = new MySqlMultiQueryParser(new PrependLeadingComments());

$sql = "-- create the users table\nCREATE TABLE users (id INT);";

foreach ($parser->parseString($sql) as $query) {
    echo $query; // "-- create the users table\nCREATE TABLE users (id INT)"
}