Database · Imports
Database imports examples.
Package-local, copy-ready examples organized like the classes and methods reference. Open one example at a time, search by method, and jump from the right-side index.
Database individual library
Imports examples with copy-ready, production-minded PHP.
Every snippet uses mnb/mnb-phpexcel-database or its declared Core dependency. Each copied snippet includes strict typing, a concise summary, implementation guidance, readable limits, and a safe fixture check.
- 3
- examples
- 3
- documented methods
SqlImporter::importRows()<?php
declare(strict_types=1);
/*
Summary:
Import associative rows from any installed reader or application source into a database table.
Implementation note:
The Database library accepts rows; it does not install a source format reader. Add CSV, XLS,
XLSX, JSON, XML, or ODS only when needed.
*/
use Mnb\PHPExcel\Import\SqlImporter;
$result = (new SqlImporter())->importRows(
$pdo,
'products',
$rows,
[
'batch_size' => 500,
'duplicate_strategy' => 'update',
'unique_by' => ['sku'],
'skip_invalid_rows' => true,
]
);SqlImporter::importRows()<?php
declare(strict_types=1);
/*
Summary:
Validate normalization and SQL batch planning without executing insert statements.
Implementation note:
Run the dry path before persistence when users choose or confirm mappings in an import UI.
*/
use Mnb\PHPExcel\Import\SqlImporter;
$result = (new SqlImporter())->importRows($pdo, 'customers', $rows, [
'map' => [
'Customer ID' => 'customer_id',
'Full Name' => 'name',
'Email Address' => 'email',
],
'dry_run' => true,
]);
print_r($result);DomainImporter::create()DomainImporter::preview()<?php
declare(strict_types=1);
/*
Summary:
Inspect detected headers, suggested mappings, and sample rows for a built-in domain preset.
Implementation note:
A file-based preview requires the matching format reader to be installed alongside Database.
*/
use Mnb\PHPExcel\Domain\DomainImportType;
use Mnb\PHPExcel\Import\DomainImporter;
$importer = DomainImporter::create();
$preview = $importer->preview(DomainImportType::Products, 'products.xlsx', [
'preview_rows' => 20,
'header_row' => 'auto',
'header_detection_rows' => 25,
'mapping_min_confidence' => 0.60,
]);
print_r($preview['mapping']);
print_r($preview['sample_rows']);No matching example found.Try a method name, task, or result.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue