MNB PHPExcelDeveloper Guide
v2.0.5
Database module

Database Module

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

Updated

LevelBeginnerReading time8 minPackagemnb/mnb-phpexcel
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:^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:^2.0 plus mnb/mnb-phpexcel:^2.0
Native XLS rows into PDOmnb/mnb-phpexcel:^2.0 plus Database
Normal XLSX rows into PDOmnb/mnb-phpexcel:^2.0 plus Database
Very large XLSX direct streamingmnb/mnb-phpexcel:^2.0
Complete facade and every integrationmnb/mnb-phpexcel:^2.0 or mnb/mnb-phpexcel:^2.0