PHPackages                             nitecon/zf2-db-session - 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. nitecon/zf2-db-session

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

nitecon/zf2-db-session
======================

Zend Framework 2 database session storage

1.0.5(12y ago)204.8k13New BSD LicensePHPPHP &gt;=5.3.3

Since Mar 29Pushed 3y ago6 watchersCompare

[ Source](https://github.com/Nitecon/DBSessionStorage)[ Packagist](https://packagist.org/packages/nitecon/zf2-db-session)[ Docs](https://github.com/Nitecon/DBSessionStorage)[ RSS](/packages/nitecon-zf2-db-session/feed)WikiDiscussions master Synced 1mo ago

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

DBSessionStorage
================

[](#dbsessionstorage)

Zend Framework Module for storing sessions in database.

Features
--------

[](#features)

- Easy to use module for getting your sessions into a database
- Uses Laminas\\Session\\SaveHandler\\DbTableGateway
- Uses your already available DB Configuration
- Provides configurable session options

Setup
-----

[](#setup)

The following steps are necessary to get this module working

1. Run `php composer.phar require nitecon/zf2-db-session:1.*`
2. Add `DBSessionStorage` to the enabled modules list
3. Add the sessions table to your database with: ```
    CREATE TABLE IF NOT EXISTS ```
    sessions
    ``` (
    ```
    id
    ``` char(32) NOT NULL DEFAULT '',
    ```
    name
    ``` varchar(255) NOT NULL,
    ```
    modified
    ``` int(11) DEFAULT NULL,
    ```
    lifetime
    ``` int(11) DEFAULT NULL,
    ```
    data
    ``` text,
    PRIMARY KEY (```
    id
    ```)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    ```
4. Copy `vendor/nitecon/zf2-db-session/dbsession.global.php.dist` to `config/autoload/dbsession.global.php`
5. Configure the session options in `config/autoload/dbsession.global.php`

Addditional Information
-----------------------

[](#addditional-information)

This module assumes that you already have a top level *db* key in your configuration like the following:

```
    return array(
    'db' => array(
        'driver' => 'Pdo',
        'dsn' => 'mysql:dbname=somedb;host=localhost',
        'username' => 'sessionuser',
        'password' => 'sessionpass',
        'driver_options' => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'',
            'buffer_results' => true
        ),
    ),
    /* Rest of your config */
    );
```

If you do not have this configuration please make sure to add it based on your database details, and always remember to put your username and password details in the local.php file so that it is not added to the revision control system that you use.

Gotchas and Errors
------------------

[](#gotchas-and-errors)

If you see the error that looks something like: Laminas\\Session\\SessionManager 'Insufficient data for unserializing' It means that the data being inserted into the database is larger than what the column allows for it.

To fix this issue adjust the 'data' column in your database from 'text' -&gt; 'blob', On some of my applications that store a good amount of data in the session I've noticed that with some ZF2 overhead on the session they are generally around 1.5kb in size which generates this error.

Final notes
-----------

[](#final-notes)

Please note that the driver as listed above does not need to be Pdo it can be anything that Zend Adapter supports, however it has only been tested with a Pdo / Mysqli driver.

I'm also planning on adding another module for doctrine based database interface in the future for those that are interested.

Enjoy and if you find bugs or issues please add pull requests for the module.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 69.2% 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 ~48 days

Total

5

Last Release

4596d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/41178212476488fd2bf9164bebb3b66655442f64c746a4b11dc9fa0cc822215d?d=identicon)[Nitecon](/maintainers/Nitecon)

---

Top Contributors

[![nitecon](https://avatars.githubusercontent.com/u/665977?v=4)](https://github.com/nitecon "nitecon (9 commits)")[![gitkdm](https://avatars.githubusercontent.com/u/108815397?v=4)](https://github.com/gitkdm "gitkdm (3 commits)")[![jonrwads](https://avatars.githubusercontent.com/u/997151?v=4)](https://github.com/jonrwads "jonrwads (1 commits)")

---

Tags

databasestoragedbsessionzf2

### Embed Badge

![Health badge](/badges/nitecon-zf2-db-session/health.svg)

```
[![Health](https://phpackages.com/badges/nitecon-zf2-db-session/health.svg)](https://phpackages.com/packages/nitecon-zf2-db-session)
```

###  Alternatives

[rah/danpu

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

64401.8k10](/packages/rah-danpu)[dmstr/yii2-db

Database extensions

19618.8k6](/packages/dmstr-yii2-db)[tawfekov/zf2entityaudit

EntityAudit Module for Zend Framework2 , Doctrine2 and web interface

1910.4k](/packages/tawfekov-zf2entityaudit)

PHPackages © 2026

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