PHPackages                             mauretto78/db-importer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mauretto78/db-importer

ActiveLibrary[Database &amp; ORM](/categories/database)

mauretto78/db-importer
======================

In Memory List

v1.2.3(8y ago)0290MITPHPPHP ^5.6 || ^7.0

Since Feb 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mauretto78/db-importer)[ Packagist](https://packagist.org/packages/mauretto78/db-importer)[ Docs](https://github.com/mauretto78/db-importer)[ RSS](/packages/mauretto78-db-importer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (9)Dependencies (8)Versions (10)Used By (0)

Db-Importer
===========

[](#db-importer)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/bc2f015c7ffa69210bc3b8391996a9af4d6647dcf2a44bd9f78ec436afaaf394/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6175726574746f37382f64622d696d706f727465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mauretto78/db-importer/?branch=master)[![Build Status](https://camo.githubusercontent.com/028c7d8938282e3b625d04f77a4c0aac367932aa88bf21241981a5b89d9a865f/68747470733a2f2f7472617669732d63692e6f72672f6d6175726574746f37382f64622d696d706f727465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mauretto78/db-importer)[![Codacy Badge](https://camo.githubusercontent.com/83ddc31f1363fcd370d038aa0a6529d1b2fccd18b833792b1f92767f98ebfa16/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3631343434623832353965363432663939303936356663383433323833616437)](https://www.codacy.com/app/mauretto78/db-importer?utm_source=github.com&utm_medium=referral&utm_content=mauretto78/db-importer&utm_campaign=Badge_Grade)![license](https://camo.githubusercontent.com/205618592da264c163af994cdd2630ecfaa43bc47c6bba66abff8e31d780550f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6175726574746f37382f64622d696d706f727465722e737667)![Packagist](https://camo.githubusercontent.com/08a77f130c423c2d332efd1867f7f3cdee38344764ef69f62d7e9787b65022a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6175726574746f37382f64622d696d706f727465722e737667)

This library allows you to import data in your database with very low effort.

Basic Usage
-----------

[](#basic-usage)

To use Importer simply do this:

```
use DbImporter\Importer;

// init Importer
$importer = Importer::init(
    $connection, // your DBAL connection
    $table,      // table to import data
    $mapping,    // mapping array
    $data,       // input data
    $ignoreErr,  // ignore errors (boolean). True is default value
    $mode        // insert mode. 'single' or 'multiple' are the only values allowed. 'multiple' is default value
);

// execute import query
$importer->execute()
```

Please note that you must pass a [DBAL Connection](http://www.doctrine-project.org/projects/dbal.html) instance to Importer class.

### Avaliable drivers

[](#avaliable-drivers)

Currently the supported drivers are:

- `pdo_mysql` (MySQL)
- `pdo_pgsql` (PostgreSQL)
- `pdo_sqlite` (Sqlite)

### Mapping array

[](#mapping-array)

The mapping array is a simple key value array in which you specify the column name on your database's table and the corresponding key in the input data. Look at the following example:

```
$mapping = [
    'id' => 'id_utente',             // 'id' is the column name on your database's table. 'id_utente' is the key in input data
    'name' => 'name_utente',         // 'name' is the column name on your database's table. 'name_utente' is the key in input data
    'username' => 'username_utente', // 'username' is the column name on your database's table. 'username_utente' is the key in input data
    'email' => 'email_utente',       // 'email' is the column name on your database's table. 'email_utente' is the key in input data
];
```

### Data

[](#data)

The only requirement is the input data must be iterable (array or object). Here's the most simple example:

```
// as simple associative array
$data = [
    [
        'id_utente' => 1,
        'name_utente' => 'Mauro',
        'email_utente' => 'assistenza@easy-grafica.com',
        'username_utente' => 'mauretto78',
    ],
    [
        'id_utente' => 2,
        'name_utente' => 'John',
        'email_utente' => 'john@doe.com',
        'username_utente' => 'johndoe',
    ],
    [
        'id_utente' => 3,
        'name_utente' => 'Maria',
        'email_utente' => 'maria@key.com',
        'username_utente' => 'maria',
    ]
];

//..
```

#### Working with Entities

[](#working-with-entities)

You can use as your feed data an iterable object of entities. **Getters are required**. Look at the following example:

```
// User entity
final class User
{
    /**
     * @var int
     */
    private $id;

    /**
     * @var string
     */
    private $name;

    /**
     * @var string
     */
    private $email;

    /**
     * @var string
     */
    private $username;

    /**
     * User constructor.
     * @param $id
     * @param $name
     * @param $email
     * @param $username
     */
    public function __construct(
        $id,
        $name,
        $email,
        $username
    ) {
        $this->id = $id;
        $this->name = $name;
        $this->email = $email;
        $this->username = $username;
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * @return string
     */
    public function getUsername()
    {
        return $this->username;
    }
}

// use Doctrine\ArrayCollection as feed of Importer
$data = new ArrayCollection([
    new User(
        1,
        'Mauro',
        'assistenza@easy-grafica.com',
        'mauretto78'
    ),
    new User(
        2,
        'John',
        'john@doe.com',
        'johndoe'
    ),
    new User(
        3,
        'Maria',
        'maria@key.com',
        'maria'
    )
]);

//..
```

### Insert Mode (multiple or single)

[](#insert-mode-multiple-or-single)

You can decide how to build insert query:

- 'multiple' (default) - insert data in a unique multiple insert query
- 'single' - insert data in a loop of insert queries

### Limit of records in multiple insert queries

[](#limit-of-records-in-multiple-insert-queries)

Please note that there is a limit to the maximum number of records that can be inserted in a single query. In case this limit is exceeded, a loop of multiple insertion queries will be executed.

This limit is:

- 4000 records for `pdo_mysql` driver
- 4000 records for `pdo_pgsql` driver
- 200 records for `pdo_sqlite` driver

### Create Schema

[](#create-schema)

If you need to create table scheme, use `createSchema()` method. Do the following:

```
$keys = [
    'id' => 'integer',
    'album_id' => 'integer',
    'titolo' => 'string',
    'url' => 'string',
    'thumbnail_url' => 'string',
];

$uniqueKeys = ['id'];
$indexKeys = ['album_id', 'titolo'];

$importer->createSchema($keys, $uniqueKeys, $indexKeys);
```

### Destroy Schema

[](#destroy-schema)

To destroy table scheme, use `destroySchema()` method:

```
// ..

$importer->destroySchema();
```

### Clear data table

[](#clear-data-table)

If you want to clear table data (maybe before importing data), use `clearData()` method instead:

```
// ..

$importer->clearData();
```

Built With
----------

[](#built-with)

- [DBAL](http://www.doctrine-project.org/projects/dbal.html) - Database Abstraction Layer

Requirements
------------

[](#requirements)

- PHP 5.6+
- MySQL 5.7+
- PostgreSQL 9.5+

Support
-------

[](#support)

If you found an issue or had an idea please refer [to this section](https://github.com/mauretto78/db-importer/issues).

Authors
-------

[](#authors)

- **Mauro Cassani** - [github](https://github.com/mauretto78)

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

9

Last Release

2978d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a9a5d92c7a88371bdc4b5f7fb7ff9c4fe890289b970d53486ca455700614df7?d=identicon)[mauretto78](/maintainers/mauretto78)

---

Top Contributors

[![codacy-badger](https://avatars.githubusercontent.com/u/23704769?v=4)](https://github.com/codacy-badger "codacy-badger (1 commits)")

---

Tags

dbdbalimportmysqlsqlitedatabasemysqlsqlitepostgresdbalimporter

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/mauretto78-db-importer/health.svg)

```
[![Health](https://phpackages.com/badges/mauretto78-db-importer/health.svg)](https://phpackages.com/packages/mauretto78-db-importer)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M35](/packages/scienta-doctrine-json-functions)[nettrine/dbal

Doctrine DBAL for Nette Framework

322.6M19](/packages/nettrine-dbal)[cycle/database

DBAL, schema introspection, migration and pagination

64690.9k31](/packages/cycle-database)[aura/sqlschema

Provides facilities to read table names and table columns from a database using PDO.

41234.1k4](/packages/aura-sqlschema)[chillerlan/php-database

An extensible database wrapper and query builder.

431.2k2](/packages/chillerlan-php-database)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
