asika / sql-splitter
This is a class that can split BIG SQL file or string as iterator so that can help us save memory when importing SQL to database.
Installs: 4 391
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ^6.5
- windwalker/http: ^3.4
- windwalker/test: ^3.4
Suggests
- psr/http-message: Install ^1.0 to support PSR-7 Stream.
This package is auto-updated.
Last update: 2024-11-11 10:38:17 UTC
README
This is a class that can split BIG SQL file or string as iterator so that can help us save memory when importing SQL to database.
Install
composer require asika/sql-splitter
Usage
use Asika\SqlSplitter\SqlSplitter; $it = SqlSplitter::splitFromFile(__DIR__ . '/path/to/db.sql'); // Loop iterator foreach ($it as $query) { if (trim($query) !== '') { $db->prepare($query)->execute(); } } // Or just convert to array $queries = iterator_to_array($it); // Available methods SqlSplitter::splitSqlString('...'); SqlSplitter::splitFromFile('path/to/fil.sql'); SqlSplitter::splitFromPsr7Stream(new Stream('zip://file.zip#backup.sql')); SqlSplitter::splitFromStream(fopen('s3://...', 'r'));
To use PSR-7 Stream, you must install
psr/http-message