{"id":28300278,"url":"https://github.com/mauretto78/db-importer","last_synced_at":"2026-04-16T10:35:23.324Z","repository":{"id":62525374,"uuid":"120014944","full_name":"mauretto78/db-importer","owner":"mauretto78","description":"Db Importer is a library that allows you to import data in your database with very low effort","archived":false,"fork":false,"pushed_at":"2018-03-14T11:20:12.000Z","size":104,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-28T19:35:37.522Z","etag":null,"topics":["db","dbal","import","mysql","sqlite"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mauretto78.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-02T18:13:01.000Z","updated_at":"2018-03-14T11:19:51.000Z","dependencies_parsed_at":"2022-11-02T15:45:38.453Z","dependency_job_id":null,"html_url":"https://github.com/mauretto78/db-importer","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/mauretto78/db-importer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauretto78%2Fdb-importer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauretto78%2Fdb-importer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauretto78%2Fdb-importer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauretto78%2Fdb-importer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mauretto78","download_url":"https://codeload.github.com/mauretto78/db-importer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mauretto78%2Fdb-importer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31882632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T09:23:21.276Z","status":"ssl_error","status_checked_at":"2026-04-16T09:23:15.028Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["db","dbal","import","mysql","sqlite"],"created_at":"2025-05-23T15:20:37.830Z","updated_at":"2026-04-16T10:35:23.316Z","avatar_url":"https://github.com/mauretto78.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Db-Importer\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mauretto78/db-importer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mauretto78/db-importer/?branch=master)\n[![Build Status](https://travis-ci.org/mauretto78/db-importer.svg?branch=master)](https://travis-ci.org/mauretto78/db-importer)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/61444b8259e642f990965fc843283ad7)](https://www.codacy.com/app/mauretto78/db-importer?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=mauretto78/db-importer\u0026amp;utm_campaign=Badge_Grade)\n[![license](https://img.shields.io/github/license/mauretto78/db-importer.svg)]()\n[![Packagist](https://img.shields.io/packagist/v/mauretto78/db-importer.svg)]()\n\nThis library allows you to import data in your database with very low effort.\n\n## Basic Usage\n\nTo use Importer simply do this:\n\n```php\nuse DbImporter\\Importer;\n\n// init Importer\n$importer = Importer::init(\n    $connection, // your DBAL connection\n    $table,      // table to import data\n    $mapping,    // mapping array\n    $data,       // input data\n    $ignoreErr,  // ignore errors (boolean). True is default value\n    $mode        // insert mode. 'single' or 'multiple' are the only values allowed. 'multiple' is default value\n);\n\n// execute import query\n$importer-\u003eexecute()\n\n```\n\nPlease note that you must pass a [DBAL Connection](http://www.doctrine-project.org/projects/dbal.html) instance to Importer class.\n\n### Avaliable drivers\n \nCurrently the supported drivers are:\n\n* `pdo_mysql` (MySQL)\n* `pdo_pgsql` (PostgreSQL)\n* `pdo_sqlite` (Sqlite)\n\n### Mapping array\n\nThe 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:\n\n```php\n$mapping = [\n    'id' =\u003e 'id_utente',             // 'id' is the column name on your database's table. 'id_utente' is the key in input data\n    'name' =\u003e 'name_utente',         // 'name' is the column name on your database's table. 'name_utente' is the key in input data\n    'username' =\u003e 'username_utente', // 'username' is the column name on your database's table. 'username_utente' is the key in input data\n    'email' =\u003e 'email_utente',       // 'email' is the column name on your database's table. 'email_utente' is the key in input data\n];\n\n```\n\n### Data\n\nThe only requirement is the input data must be iterable (array or object). Here's the most simple example:\n\n```php\n// as simple associative array\n$data = [\n    [\n        'id_utente' =\u003e 1,\n        'name_utente' =\u003e 'Mauro',\n        'email_utente' =\u003e 'assistenza@easy-grafica.com',\n        'username_utente' =\u003e 'mauretto78',\n    ],\n    [\n        'id_utente' =\u003e 2,\n        'name_utente' =\u003e 'John',\n        'email_utente' =\u003e 'john@doe.com',\n        'username_utente' =\u003e 'johndoe',\n    ],\n    [\n        'id_utente' =\u003e 3,\n        'name_utente' =\u003e 'Maria',\n        'email_utente' =\u003e 'maria@key.com',\n        'username_utente' =\u003e 'maria',\n    ]\n];\n\n//..\n```\n\n#### Working with Entities\n\nYou can use as your feed data an iterable object of entities. **Getters are required**. Look at the following example:\n\n```php\n// User entity\nfinal class User\n{\n    /**\n     * @var int\n     */\n    private $id;\n\n    /**\n     * @var string\n     */\n    private $name;\n\n    /**\n     * @var string\n     */\n    private $email;\n\n    /**\n     * @var string\n     */\n    private $username;\n\n    /**\n     * User constructor.\n     * @param $id\n     * @param $name\n     * @param $email\n     * @param $username\n     */\n    public function __construct(\n        $id,\n        $name,\n        $email,\n        $username\n    ) {\n        $this-\u003eid = $id;\n        $this-\u003ename = $name;\n        $this-\u003eemail = $email;\n        $this-\u003eusername = $username;\n    }\n\n    /**\n     * @return int\n     */\n    public function getId()\n    {\n        return $this-\u003eid;\n    }\n\n    /**\n     * @return string\n     */\n    public function getName()\n    {\n        return $this-\u003ename;\n    }\n\n    /**\n     * @return string\n     */\n    public function getEmail()\n    {\n        return $this-\u003eemail;\n    }\n\n    /**\n     * @return string\n     */\n    public function getUsername()\n    {\n        return $this-\u003eusername;\n    }\n}\n\n// use Doctrine\\ArrayCollection as feed of Importer\n$data = new ArrayCollection([\n    new User(\n        1,\n        'Mauro',\n        'assistenza@easy-grafica.com',\n        'mauretto78'\n    ),\n    new User(\n        2,\n        'John',\n        'john@doe.com',\n        'johndoe'\n    ), \n    new User(\n        3,\n        'Maria',\n        'maria@key.com',\n        'maria'\n    )\n]);\n\n//..\n```\n\n### Insert Mode (multiple or single)\n\nYou can decide how to build insert query:\n \n* 'multiple' (default) - insert data in a unique multiple insert query\n* 'single' - insert data in a loop of insert queries\n \n### Limit of records in multiple insert queries\n \nPlease 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. \n\nThis limit is:\n\n* 4000 records for `pdo_mysql` driver\n* 4000 records for `pdo_pgsql` driver\n* 200 records for `pdo_sqlite` driver\n \n### Create Schema\n\nIf you need to create table scheme, use `createSchema()` method. Do the following:\n\n```php\n$keys = [\n    'id' =\u003e 'integer',\n    'album_id' =\u003e 'integer',\n    'titolo' =\u003e 'string',\n    'url' =\u003e 'string',\n    'thumbnail_url' =\u003e 'string',\n];\n\n$uniqueKeys = ['id'];\n$indexKeys = ['album_id', 'titolo'];\n\n$importer-\u003ecreateSchema($keys, $uniqueKeys, $indexKeys);\n```\n\n### Destroy Schema\n \nTo destroy table scheme, use `destroySchema()` method:\n\n```php\n// ..\n\n$importer-\u003edestroySchema();\n```\n\n### Clear data table\n\nIf you want to clear table data (maybe before importing data), use `clearData()` method instead:\n\n```php\n// ..\n\n$importer-\u003eclearData();\n```\n\n## Built With\n\n* [DBAL](http://www.doctrine-project.org/projects/dbal.html) - Database Abstraction Layer\n\n## Requirements\n\n* PHP 5.6+\n* MySQL 5.7+\n* PostgreSQL 9.5+\n\n## Support\n\nIf you found an issue or had an idea please refer [to this section](https://github.com/mauretto78/db-importer/issues).\n\n## Authors\n\n* **Mauro Cassani** - [github](https://github.com/mauretto78)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauretto78%2Fdb-importer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmauretto78%2Fdb-importer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmauretto78%2Fdb-importer/lists"}