PHPackages                             idct/php-db-csv-writer - 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. idct/php-db-csv-writer

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

idct/php-db-csv-writer
======================

Library which simplifies bulk data loading into MySQL-compatible database engines using CSV collections.

1.0.2(6y ago)02.0kMITPHPPHP &gt;=7.1CI failing

Since Nov 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/bpacholek/php-db-csv-writer)[ Packagist](https://packagist.org/packages/idct/php-db-csv-writer)[ RSS](/packages/idct-php-db-csv-writer/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (6)Versions (4)Used By (0)

PHP DB CSV Writer
=================

[](#php-db-csv-writer)

PHP library which makes the process of CSV data files imports into MySQL easier.

[![Tests status](https://github.com/ideaconnect/php-db-csv-writer/workflows/All%20tests%20using%20PHPUnit/badge.svg)](https://github.com/ideaconnect/php-db-csv-writer/workflows/All%20tests%20using%20PHPUnit/badge.svg) [![Coverage Status](https://camo.githubusercontent.com/7586b77137907d52b6379c9edf6695e908fcf6d48afcb89ca0b2bf7948d1d08b/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f69646561636f6e6e6563742f7068702d64622d6373762d7772697465722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/ideaconnect/php-db-csv-writer?branch=master) [![GitHub tag (latest SemVer)](https://camo.githubusercontent.com/8376a4f4d3c188d37b1a41e1e7ce544e068901c835fabd47e07b718093792eca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f69646561636f6e6e6563742f7068702d64622d6373762d7772697465723f6c6162656c3d6c617465737425323076657273696f6e26736f72743d73656d766572)](https://camo.githubusercontent.com/8376a4f4d3c188d37b1a41e1e7ce544e068901c835fabd47e07b718093792eca/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f69646561636f6e6e6563742f7068702d64622d6373762d7772697465723f6c6162656c3d6c617465737425323076657273696f6e26736f72743d73656d766572)

Allows easy building of ready-to-import CSV collections for MySQL-compatible (like MariaDB etc.) PDO-accessible database connections.

You can add new data entries into the collection by calling `appendData(array)` and later load the file into the database by calling `storeCollection`.

Installation
------------

[](#installation)

The best way to install the library in your project is by using **Composer**:

```
composer require idct/php-db-csv-writer
```

of course you can still manually include all the required files in your project using `using` statements yet **Composer** and autoloading is more than suggested.

Usage
-----

[](#usage)

Create an instance:

```
use IDCT\CsvWriter\DbCsvWriter;
$dbCsvWriter = new DbCsvWriter();
```

Assign a valid MySQL-compatible PDO connection usign `setPdo` method.

As there are files created you need to assign a temporary storage folder using `setTmpDir` method. If you will not specify any then system's temp directory shall be used.

### Starting a new collection

[](#starting-a-new-collection)

Use the `startCollection` method. It takes collection name as first argument and fields as the second. Colllection name is a handle for you: it does not need to match any table's name etc.; fields array must match fields' names in the future target table.

```
$dbCsvWriter->startCollection('firstcollection',['fieldA', 'fieldB']);
```

This will create a file `firstcollection.csv` in the storage directory set before. Any previously opened collection will be closed.

### Opening a collection

[](#opening-a-collection)

To assign a previously created collection to the instance use `openCollection`:

```
$dbCsvWriter->openCollection($name);
```

Where name can be a handle to a collection in the storage directory (for example it would `firstcollection` if you would like to open the collection from the previous point). It can also be a full path to a csv file.

### Closing and removing the collection

[](#closing-and-removing-the-collection)

To close the collection without storing use `closeCollection` method. If you call it without any arguments:

```
$dbCsvWriter->closeCollection();
```

then collection will remain assigned which further allows to remove it easily by calling

```
$dbCsvWriter->removeCollection();
```

If you first detach it by calling:

```
$dbCsvWriter->closeCollection(true);
```

then you cannot remove it afterwards.

### Storing the collection in the database

[](#storing-the-collection-in-the-database)

To save (load into the database) the collection in the database call:

```
$dbCsvWriter->storeCollection();

```

It will automatically close the collection (which flushes data into the file) and invoke `LOAD DATA INFILE` command on the databaes with the currently assigned collection.

**Warning:** by default it uses the **LOCAL** attribute in the query which informs the connector that file is stored on client's side (where the invoking computer is). If for some reason you want to load a file which is on an remote database server then specify the second argument during PDO assignment:

```
$dbCsvWriter->setPdo($pdo, false);
```

Verify that with `isDbRemote` method.

### Buffering

[](#buffering)

DbCsvWriter can use in-memory data buffering before saving in the CSV file. Check `setBufferSize` and `getBufferSize` methods which are wrappers over respective methods of the `CsvWriter`.

TODO / Contribution
-------------------

[](#todo--contribution)

At the moment the main requirement is to provide better unit tests and documentation, yet if you find any bugs or have potential feature ideas then please use Issues or Pull Requests, it is more than welcome! I will try to reply ASAP.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

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 ~32 days

Total

3

Last Release

2308d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b76a5fac115d24d698d09cc939a6922bf309732ae61d0f2f215ae9e7397658ea?d=identicon)[ideaconnect](/maintainers/ideaconnect)

---

Tags

databasemysqlmariadbcsvioimporttextbulkidcteolbulk-importtextwritercsvwriter

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/idct-php-db-csv-writer/health.svg)

```
[![Health](https://phpackages.com/badges/idct-php-db-csv-writer/health.svg)](https://phpackages.com/packages/idct-php-db-csv-writer)
```

###  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)[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

64401.8k10](/packages/rah-danpu)[mozex/laravel-scout-bulk-actions

A Laravel Scout extension for bulk importing and flushing of all models.

1033.4k](/packages/mozex-laravel-scout-bulk-actions)[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)
