PHPackages                             isaacdew/load-data - 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. isaacdew/load-data

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

isaacdew/load-data
==================

Fluent syntax for loading large CSV files into MySQL using LOAD DATA INFILE in Laravel.

0.1.1(2y ago)2181MITPHP

Since Mar 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/isaacdew/load-data)[ Packagist](https://packagist.org/packages/isaacdew/load-data)[ RSS](/packages/isaacdew-load-data/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Introduction
============

[](#introduction)

MySQL and MariaDB come equipped with the [LOAD DATA INFILE](https://mariadb.com/kb/en/load-data-infile/) statement which allows for loading large datasets from a CSV or similar file into a table very quickly. This package provides an API for constructing and executing a `LOAD DATA INFILE` statement in Laravel.

Installation
============

[](#installation)

Install this package using composer:

`composer require isaacdew/load-data`

Examples
========

[](#examples)

Basic Example
-------------

[](#basic-example)

```
use Isaacdew\LoadData\LoadData;

LoadData::from(storage_path('path/to/file.csv'))
    ->to('tablename')
    ->fieldsTerminatedBy(',')
    ->fieldsEnclosedBy('"', optionally: true)
    ->load();
```

Ignoring the CSV Header
-----------------------

[](#ignoring-the-csv-header)

```
use Isaacdew\LoadData\LoadData;

LoadData::from(storage_path('path/to/file.csv'))
    ->to('tablename')
    ->ignoreHeader()
    ->load();
```

Defining Columns
----------------

[](#defining-columns)

```
use Isaacdew\LoadData\LoadData;

LoadData::from(storage_path('path/to/file.csv'))
    ->to('tablename')
    ->fieldsTerminatedBy(',')
    ->fieldsEnclosedBy('"', optionally: true)
    ->columns([
        'column_one',
        'column_two',
        'column_three'
    ])
    ->load();
```

Using the Headers from the CSV to Define Your Columns
-----------------------------------------------------

[](#using-the-headers-from-the-csv-to-define-your-columns)

```
use Isaacdew\LoadData\LoadData;

LoadData::from(storage_path('path/to/file.csv'))
    ->to('tablename')
    ->fieldsTerminatedBy(',')
    ->fieldsEnclosedBy('"', optionally: true)
    ->useFileHeaderForColumns()
    ->load();
```

By default, the CSV headers are converted to snake case since the columns need to match your database table column names. If you need to do any custom modification, you can pass a callback to the `useFileHeaderForColumns` method.

```
use Isaacdew\LoadData\LoadData;

LoadData::from(storage_path('path/to/file.csv'))
    ->to('tablename')
    ->fieldsTerminatedBy(',')
    ->fieldsEnclosedBy('"', optionally: true)
    // Remove parenthesis from column names
    ->useFileHeaderForColumns(fn($column) => preg_replace('/(\(.*)$/', '', $column))
    ->load();
```

Only Loading Specific Columns from the CSV
------------------------------------------

[](#only-loading-specific-columns-from-the-csv)

```
use Isaacdew\LoadData\LoadData;

LoadData::from(storage_path('path/to/file.csv'))
    ->to('tablename')
    ->fieldsTerminatedBy(',')
    ->fieldsEnclosedBy('"', optionally: true)
    ->useFileHeaderForColumns()
    ->onlyColumns([
        'column_one',
        'column_two'
    ])
    ->load();
```

Truncating the Table Before Load
--------------------------------

[](#truncating-the-table-before-load)

```
use Isaacdew\LoadData\LoadData;

LoadData::from(storage_path('path/to/file.csv'))
    ->to('tablename')
    ->truncateBeforeLoad()
    ->load();
```

Using Set Statements
--------------------

[](#using-set-statements)

To use this feature, you must define the columns first either with the `columns` method or by using the file header with the `useFileHeaderForColumns` method. Then you can modify the value from your CSV using a MySQL expression. A good use case is a date column where the CSV isn't using a MySQL friendly format. Note that you must prefix the column name with `@` to use it in your expression.

```
use Isaacdew\LoadData\LoadData;

LoadData::from(storage_path('path/to/file.csv'))
    ->to('tablename')
    ->fieldsTerminatedBy(',')
    ->fieldsEnclosedBy('"', optionally: true)
    ->columns([
        'column_one',
        'column_two',
        'column_three',
        'date_column'
    ])
    ->setColumn('date_column', "STR_TO_DATE(@date_column, '%c/%d/%Y')") // Convert MM/DD/YYYY to a MySQL date
    ->load();
```

Dedicated Database Servers
==========================

[](#dedicated-database-servers)

If your Laravel application is not on the same server as your database, you will have to make sure the [LOAD DATA LOCAL INFILE](https://mariadb.com/kb/en/load-data-infile/#load-data-local-infile) statement is enabled on your database server and in PDO. This package will automatically use the `LOCAL` keyword if your `DB_HOST` is not set to `127.0.0.1` or `localhost`.

To enable `LOAD DATA LOCAL INFILE` in PDO, go to your `config/database.php` file and add `PDO::MYSQL_ATTR_LOCAL_INFILE => true` to the array of options for the `mysql` connection like so:

```
return [
    'connections' => [
        //...
        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
                PDO::MYSQL_ATTR_LOCAL_INFILE => true // Add this line!
            ]) : [],
        ],
        //...
    ]
];
```

Note On Security
================

[](#note-on-security)

Prepared statements are not supported for `LOAD DATA INFILE` statements. With that being the case, **do not use user input for constructing a `LOAD DATA INFILE` statement**. I took the precaution of using `PDO::quote()` to escape the filename, however, I would still recommend against the use of a user provided filename in this statement.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

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

Total

2

Last Release

839d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9aec44f4a61e60edaedd15ce951a0a316cbb813a07b6c604790311c4abdb40db?d=identicon)[isaacdew](/maintainers/isaacdew)

---

Top Contributors

[![isaacdew2](https://avatars.githubusercontent.com/u/43962295?v=4)](https://github.com/isaacdew2 "isaacdew2 (18 commits)")

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/isaacdew-load-data/health.svg)

```
[![Health](https://phpackages.com/badges/isaacdew-load-data/health.svg)](https://phpackages.com/packages/isaacdew-load-data)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198741.5k12](/packages/pgvector-pgvector)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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