PHPackages                             tnapf/mysqlsessions - 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. tnapf/mysqlsessions

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

tnapf/mysqlsessions
===================

A sessioninterface implementation for storing sessions in a mysql database

v0.1.0(3y ago)013MITPHP

Since Feb 13Pushed 3y agoCompare

[ Source](https://github.com/tnapf/MySQLSessions)[ Packagist](https://packagist.org/packages/tnapf/mysqlsessions)[ RSS](/packages/tnapf-mysqlsessions/feed)WikiDiscussions main Synced 1mo ago

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

Tnapf/MySQLSessions
===================

[](#tnapfmysqlsessions)

A sessioninterfaces implementation for using a MySQL database as session storage

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

[](#installation)

`composer require tnapf/mysqlsessions`

Usage
=====

[](#usage)

Setting up table
----------------

[](#setting-up-table)

First, use this SQL code to create your sessions table

```
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;

CREATE TABLE `sessions` (
  `id` varchar(16) NOT NULL,
  `data` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL CHECK (json_valid(`data`)),
  `expires` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

ALTER TABLE `sessions`
  ADD PRIMARY KEY (`id`);
COMMIT;
```

Creating Session Controller
---------------------------

[](#creating-session-controller)

Next create a PDO Connection (will be using `tnapf/pdo` for building the driver)

```
use Tnapf\Pdo\Driver;
use Tnapf\MysqlSessions\Controller;

$driver = Driver::createMySqlDriver("root", "password", "database")->connect();

/** @var PDO $driver */
$driver = $driver->driver;

$sessions = new Controller($driver);
```

After creating the driver construct `Tnapf\MysqlSessions\Controller` using the PDO object as the first argument.

Creating a session
------------------

[](#creating-a-session)

```
$session = $session->create(); // you can supply a timestamp in seconds for when the cookie should expire; default is 7 days

header($session->setCookieHeader()); // sends a set-cookie header with the session id
```

Setting session variables
-------------------------

[](#setting-session-variables)

```
$session->var = "foo";

// or

$session->set("var", "foo");
```

Unsetting session variables
---------------------------

[](#unsetting-session-variables)

```
unset($session->var);

// or

$session->unset("var");
```

Deleting sessions
-----------------

[](#deleting-sessions)

```
$sessions->delete($session);

// or

$sessions->delete($session->id);
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 57.1% 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

Unknown

Total

1

Last Release

1189d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c1dc8515485fa64088fdfa03dd0f487d507dc1516824c31be2626a6ee25244dd?d=identicon)[command\_string](/maintainers/command_string)

---

Top Contributors

[![CommandString](https://avatars.githubusercontent.com/u/44886996?v=4)](https://github.com/CommandString "CommandString (8 commits)")[![xHeaven](https://avatars.githubusercontent.com/u/14284867?v=4)](https://github.com/xHeaven "xHeaven (6 commits)")

### Embed Badge

![Health badge](/badges/tnapf-mysqlsessions/health.svg)

```
[![Health](https://phpackages.com/badges/tnapf-mysqlsessions/health.svg)](https://phpackages.com/packages/tnapf-mysqlsessions)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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