PHPackages                             phlib/flysystem-pdo - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. phlib/flysystem-pdo

ActiveLibrary[File &amp; Storage](/categories/file-storage)

phlib/flysystem-pdo
===================

A Flysystem adapter for storing files in a database using PDO

2.1.0(3y ago)1752.2k↓25.9%2[1 issues](https://github.com/phlib/flysystem-pdo/issues)LGPL-3.0PHPPHP ^7.4 || ^8.0CI failing

Since Mar 4Pushed 1y ago5 watchersCompare

[ Source](https://github.com/phlib/flysystem-pdo)[ Packagist](https://packagist.org/packages/phlib/flysystem-pdo)[ RSS](/packages/phlib-flysystem-pdo/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (3)Versions (8)Used By (0)

phlib/flysystem-pdo
===================

[](#phlibflysystem-pdo)

[![Code Checks](https://camo.githubusercontent.com/f7288ef603e04c6cfdafd045698b8a128e0fa700fc023884c2df64d9a0676bc8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70686c69622f666c7973797374656d2d70646f2f636f64652d636865636b732e796d6c3f6c6f676f3d676974687562)](https://github.com/phlib/flysystem-pdo/actions/workflows/code-checks.yml)[![Codecov](https://camo.githubusercontent.com/959a259fa94cb06fa9c4ed41cd5462173be0f4c92a38e65f477eb7483b05ac6e/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f70686c69622f666c7973797374656d2d70646f2e7376673f6c6f676f3d636f6465636f76)](https://codecov.io/gh/phlib/flysystem-pdo)[![Latest Stable Version](https://camo.githubusercontent.com/d19b50653fcf5a47c953b11f53f32d7c2f298f4cf427244800dff4e705a9709b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70686c69622f666c7973797374656d2d70646f2e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/flysystem-pdo)[![Total Downloads](https://camo.githubusercontent.com/72f4cea04f6092440ad1b9570ce4768bcd6a1eb7a89b27663c8b4babc0844604/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70686c69622f666c7973797374656d2d70646f2e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/flysystem-pdo)[![Licence](https://camo.githubusercontent.com/5b39d15578609bbedb525731cfaca8ebdd93be3999222bc7002e6f6a5524bc25/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f666c7973797374656d2d70646f2e737667)](https://camo.githubusercontent.com/5b39d15578609bbedb525731cfaca8ebdd93be3999222bc7002e6f6a5524bc25/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f666c7973797374656d2d70646f2e737667)

This is a [PDO](https://www.php.net/manual/en/class.pdo.php) Adapter for the League's [Flysystem](https://flysystem.thephpleague.com/).

- Uses multiple tables.
- Stores files in chunks.
- Option to compress the file when stored.

This implementation is optimised for use with large files when using the streams. It avoids loading the complete file into memory, preferring to store files during operation on the local file system.

Usage
-----

[](#usage)

```
use Phlib\Flysystem\Pdo\PdoAdapter;
use League\Flysystem\Filesystem;

$pdo        = new \PDO('mysql:host=hostname;dbname=database_name', 'username', 'password');
$adapter    = new PdoAdapter($pdo);
$filesystem = new Filesystem($adapter);
```

### Configuration on `write` and `writeStream`

[](#configuration-on-write-and-writestream)

```
use League\Flysystem\Config;

$config = new Config([
    'enable_compression' => false,
    'visibility'         => AdapterInterface::VISIBILITY_PUBLIC
]);
$adapter->writeStream('/path/to/file.zip', $handle, $config);
```

Adapter Configuration
---------------------

[](#adapter-configuration)

NameTypeDefaultDescriptiontable\_prefix*String*`flysystem`Prepends all tablenames.enable\_compression*Boolean*`true`Compresses a file stored in DB.chunk\_size*Integer*`1,048,576`Changes the size of file chunks stored in bytes. Defaults to 1MB.temp\_dir*String*`sys_get_temp_dir()`Location to store temporary files when they're stored and retrieved.disable\_mysql\_buffering*Boolean*`true`Stops large file results being pulled into memory### Example

[](#example)

```
use League\Flysystem\Config;

$config = new Config([
    'table_prefix'            => 'flysystem',
    'enable_compression'      => true,
    'chunk_size'              => 1048576,
    'temp_dir'                => '/var/tmp',
    'disable_mysql_buffering' => true
]);
$adapter = new PdoAdapter($pdo, $config);
```

File Configuration
------------------

[](#file-configuration)

The following optional file configurations supplement the standard behaviour. The sample schemas include the columns, but they are optional and may be omitted.

NameTypeDescriptionexpirystringSpecify a expiry time for the filemetamixedAny additional information. Uses JSON encoding to store the information### Expiry

[](#expiry)

By specifying 'expiry' as a configuration parameter when writing or updating a file the `PdoAdatper`will store the value in a column called 'expiry'. When the information about the file is selected out, if the expiry exists and can be parsed by `strtotime`, then the expiry time will be evaluated. False is returned if the file doesn't exist or has expired.

#### Example

[](#example-1)

```
$config = new Config(['expiry' => date('Y-m-d H:i:s', strtotime('+2 days'))]);
$adapter->write($path, $content, $config);
```

The expiry is now part of the file description.

```
$data = $adapter->getMetadata($path);
[
    'path' => '...',
    '...',
    'expiry' => ''
]
```

### Additional Metadata

[](#additional-metadata)

It's possible to store additional meta data about a file or directory. This could include owner, permissions or groups for example. The information is stored as a JSON encoded string in whatever form you provide. One the item is retrieved from the Filesystem the additional meta information is provided in the same format it was originally provided.

#### Example

[](#example-2)

```
$config = new Config(['meta' => ['owner' => 'John Smith', 'permissions' => 600]]);
$adapter->write($path, $content, $config);
```

Those details are now part of the file description.

```
$data = $adapter->getMetadata($path);
[
    'path' => '...',
    '...',
    'meta' => [
        'owner' => 'John Smith',
        'permissions' => 600
    ]
]
```

Schema
------

[](#schema)

Schemas can be found in the schema directory. Specific types can be changed based on requirements. All field names should remain the same. Notes about the DB specific definitions are below.

### MySQL Notes

[](#mysql-notes)

- The `path` column is set to allow up to 255 characters.
- The `size` column has been set to a unsigned `INT` type to allow for convenient searching. This allows up to 4G files to be recorded. This can be changed to a `VARCHAR` if searching is not required.
- The size of chunks, allows for up to 16M per chunk.

Memory Usage (and gotchas)
--------------------------

[](#memory-usage-and-gotchas)

Any use of `read`, `write` or `update` with large files will cause problems with memory usage. The associated stream methods have been optimised to use as little memory as possible. The adapter first saves the file to the local filesystem before transferring it to the database.

### Buffering

[](#buffering)

On MySQL, the default behaviour is to buffer all query results. When reading a file back from the database this could cause memory problems. There is a configuration option which disables the buffering. This has the side effect that the pdo connection specified in the constructor is altered to set this attribute.

### Compression

[](#compression)

Compression is especially useful when storing text based files. The compression option defaults to on. The side effect of this is that when reading files back some files may cause larger than expected memory usage. As an example, a very large file filled with a single letter 'a', can be compressed to a tiny size. When that file is read, the tiny chunk is expanded and will fill the memory.

When a file is stored, the setting for compression is stored with it. This can not be changed.

Chunking
--------

[](#chunking)

Chunking has been implemented to aid where systems have been set up for replication. Packet sizes are a consideration here.

License
-------

[](#license)

This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see .

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 95.7% 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 ~395 days

Recently: every ~547 days

Total

7

Last Release

1403d ago

Major Versions

0.0.3 → 1.0.02017-05-15

1.1.0 → 2.0.02022-08-22

PHP version history (3 changes)0.0.1PHP &gt;=5.4.0

1.1.0PHP ^5.4|^7.0

2.0.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/135b7ddf9ec91c412e1b18174f81d1ad2bef66e732624195c156717c96b13731?d=identicon)[letssurf](/maintainers/letssurf)

![](https://www.gravatar.com/avatar/10c53cdcfb3a6d299820aecb993521cc1a972baa09fd8f31d2468908cded7e1d?d=identicon)[chrisminett](/maintainers/chrisminett)

---

Top Contributors

[![chrisminett](https://avatars.githubusercontent.com/u/1084019?v=4)](https://github.com/chrisminett "chrisminett (67 commits)")[![jdempster](https://avatars.githubusercontent.com/u/10297?v=4)](https://github.com/jdempster "jdempster (2 commits)")[![glensc](https://avatars.githubusercontent.com/u/199095?v=4)](https://github.com/glensc "glensc (1 commits)")

###  Code Quality

TestsPHPUnit

Code StyleECS

### Embed Badge

![Health badge](/badges/phlib-flysystem-pdo/health.svg)

```
[![Health](https://phpackages.com/badges/phlib-flysystem-pdo/health.svg)](https://phpackages.com/packages/phlib-flysystem-pdo)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.7k285.7M1.0k](/packages/league-flysystem-aws-s3-v3)[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.5M85](/packages/unisharp-laravel-filemanager)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[league/flysystem-bundle

Symfony bundle integrating Flysystem into Symfony applications

40432.5M138](/packages/league-flysystem-bundle)[alexusmai/laravel-file-manager

File manager for Laravel

1.2k803.2k9](/packages/alexusmai-laravel-file-manager)

PHPackages © 2026

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