asika / sql-splitter
这是一个可以将大SQL文件或字符串拆分成迭代器的类,这样在将SQL导入数据库时可以节省内存。
1.0.0
2020-01-09 04:11 UTC
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-09-11 10:17:43 UTC
README
这是一个可以将大SQL文件或字符串拆分成迭代器的类,这样在将SQL导入数据库时可以节省内存。
安装
composer require asika/sql-splitter
用法
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'));
要使用PSR-7流,您必须安装
psr/http-message