PHPackages                             programster/mysql-session-handler - 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. programster/mysql-session-handler

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

programster/mysql-session-handler
=================================

MySQL PHP Session Handler

1.0.2(5y ago)67.1k↑146.7%6[1 PRs](https://github.com/programster/PHP-MySQL-Session-Handler/pulls)MITPHPPHP &gt;=7.0.0

Since Oct 6Pushed 2y ago1 watchersCompare

[ Source](https://github.com/programster/PHP-MySQL-Session-Handler)[ Packagist](https://packagist.org/packages/programster/mysql-session-handler)[ Docs](https://github.com/programster/PHP-MySQL-Session-Handler)[ RSS](/packages/programster-mysql-session-handler/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (7)Used By (0)

PHP 7.0+ MySQL Session Handler
==============================

[](#php-70-mysql-session-handler)

This repository contains a custom PHP session handler using MySQL as a backend. There is also [an example codebase using this package](https://github.com/programster/MySQL-Sessions-Package-Demo).

How to Install
--------------

[](#how-to-install)

#### Using [Composer](http://getcomposer.org/)

[](#using-composer)

Install composer if you haven't already ([Linux instructions](http://blog.programster.org/ubuntu-install-composer)).

Navigate to your project's directory and run the following command:

```
composer require "programster/mysql-session-handler"
```

How to use
----------

[](#how-to-use)

It may be easiest just to watch this [Youtube demonstration video](https://youtu.be/avRhoo6DGA0).

Below is a script demonstrating how to use this tool.

```
require 'vendor/autoload.php';

# Create your MySQL database connection
$db = new mysqli('localhost', 'username', 'password', 'database');

# Create the session handler using that connection and pass it the name of the table
# The handler will try to create it if it doesn't already exist.
$handler = new \Programster\SessionHandler\SessionHandler($db, 'my_sessions_table');

# Tell PHP to use the handler we just created.
session_set_save_handler($handler, true);

# Start your session
session_start();

# Set a session variable.
$_SESSION['my_session_variable'] = 'some data here';
```

### Manually Creating Sessions Table

[](#manually-creating-sessions-table)

The tool will try to use the database connection to create the sessions table if it doesn't already exist. If you provide the handler with user credentials that haven't been granted the rights to create tables, you can manually create the table with the following SQL statement:

```
CREATE TABLE IF NOT EXISTS `sessions` (
    `id` varchar(32) NOT NULL,
    `modified_timestamp` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    `data` mediumtext,
    PRIMARY KEY (`id`),
    KEY `modified_timestamp` (`modified_timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
```

Authors
-------

[](#authors)

- [Programster](https://github.com/Programster)
- [Jamie Cressey](https://github.com/JamieCressey)

License
-------

[](#license)

MIT Public License

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 60% 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 ~377 days

Recently: every ~264 days

Total

6

Last Release

2037d ago

Major Versions

0.1.1 → 1.0.02018-01-14

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

0.1.0PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/64a048ca8be761aced9419279975a21ef679b71c70d8263bc2fc413a87ad381c?d=identicon)[programster](/maintainers/programster)

---

Top Contributors

[![programster](https://avatars.githubusercontent.com/u/5709838?v=4)](https://github.com/programster "programster (12 commits)")[![JamieCressey](https://avatars.githubusercontent.com/u/6462914?v=4)](https://github.com/JamieCressey "JamieCressey (8 commits)")

---

Tags

phpmysqlsessions

### Embed Badge

![Health badge](/badges/programster-mysql-session-handler/health.svg)

```
[![Health](https://phpackages.com/badges/programster-mysql-session-handler/health.svg)](https://phpackages.com/packages/programster-mysql-session-handler)
```

###  Alternatives

[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k23.2k](/packages/clouddueling-mysqldump-php)[stefangabos/zebra_database

An advanced, compact and lightweight MySQL database wrapper library, built around PHP's MySQLi extension.

11712.6k](/packages/stefangabos-zebra-database)[eftec/pdoone

Minimaist procedural PDO wrapper library

1116.3k9](/packages/eftec-pdoone)[popphp/pop-db

Pop Db Component for Pop PHP Framework

1816.5k12](/packages/popphp-pop-db)[matthew-p/docker-server

Universal docker server, Nginx, PHP-FPM, MySql, Redis

115.1k](/packages/matthew-p-docker-server)

PHPackages © 2026

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