MNB PHPExcelDeveloper Guide
Database library

Standalone Database Library

Use the standalone format-neutral PDO library for validation, mapping, domain imports, SQL batches, manifests, failed rows, and database cursors.

Updated

LevelBeginnerReading time8 minPackagemnb/mnb-phpexcel-database
SqlImporter::importRows()DomainImporter::create()DatabaseConnectionFactory::make()

What you will learn

  • Install database workflows without automatically installing XLSX.
  • Import any iterable row source into PDO.
  • Add the source format package or the database-XLSX bridge only when required.

Install the format-neutral PDO package#

Terminal
composer require mnb/mnb-phpexcel-database:^2.0

This package requires only Core and ext-pdo. It does not install XLSX or any other format reader.

Import rows from any source#

PHP
use Mnb\PHPExcel\Import\SqlImporter;

$result = (new SqlImporter())->importRows(
    $pdo,
    'customers',
    $rows,
    [
        'batch_size' => 500,
        'duplicate_strategy' => 'skip',
    ]
);

$rows may be an array, generator, database cursor, CSV session, JSON session, XML session, native XLS session, native XLSX session, or another iterable normalized by your application.

Install source formats separately#

NeedInstall
CSV rows into PDOmnb/mnb-phpexcel-database:^2.0 + mnb/mnb-phpexcel-csv:^2.0
Native XLS rows into PDOmnb/mnb-phpexcel-database:^2.0 + mnb/mnb-phpexcel-xls:^2.0
Normal XLSX rows into PDOmnb/mnb-phpexcel-database:^2.0 + mnb/mnb-phpexcel-xlsx:^2.0
Very large XLSX direct streamingmnb/mnb-phpexcel-database-xlsx:^2.0
Complete mono librarymnb/mnb-phpexcel:^2.0 instead of individual libraries