Search by

nixphp / database

floknapp

This package is abandoned and no longer maintained. The author suggests using the naf/database package instead.

NixPHP Database Plugin to work with various storage solutions.

Package info

github.com/nixphp/database

Type:nixphp-plugin

pkg:composer/nixphp/database

Statistics

Installs: 216

Dependents: 1

Suggesters: 1

Stars: 0

Open Issues: 0

v0.1.3 2026-02-22 22:50 UTC

This package is auto-updated.

Last update: 2026-09-13 19:03:39 UTC


README

Important

NixPHP is now NAF — "Not Another Framework".

This package continues as naf/database: github.com/nafphp/database · documentation · what changed and how to move

composer require naf/database

The old name collided with NixOS down to the shell, where the CLI binary was literally nix. This repository is archived and receives no further releases; nixphp/database stays on Packagist so existing installations keep working.

Note the plugin type. NAF discovers plugins by the Composer type naf-plugin. A package still declaring nixphp-plugin is not loaded — silently, with no error.

Logo

NixPHP Database Plugin

← Back to NixPHP

nixphp/database

Simple, native PDO connection for your NixPHP application.

This plugin provides a shared PDO instance via the service container, supporting both MySQL/MariaDB and SQLite out of the box — with sensible defaults.

🧩 Part of the official NixPHP plugin collection. Install it when you need a native, PSR-compliant database connection — and nothing more.

📦 Features

  • ✅ Shared PDO instance, ready to use
  • ✅ MySQL/MariaDB and SQLite support
  • ✅ Uses sane defaults (error mode, fetch mode, UTF-8 charset)
  • ✅ Works with memory databases (sqlite::memory:)
  • ✅ Available via database() helper or DI container

📥 Installation

composer require nixphp/database

Then add the following configuration to /app/config.php. You can choose between MySQL/MariaDB or SQLite.

Example: MySQL

<?php

return [
    // ...
    'database' => [
        'driver'   => 'mysql',
        'host'     => '127.0.0.1',
        'database' => 'myapp',
        'username' => 'root',
        'password' => '',
        'charset'  => 'utf8mb4',
    ]
];

Example: SQLite

<?php

return [
    // ...
    'database' => [
        'driver'   => 'sqlite',
        'database' => __DIR__ . '/../storage/database.sqlite',
    ]
];

Or for in-memory SQLite:

return [
    // ...
    'database' => [
        'driver'   => 'sqlite',
        'database' => ':memory:',
    ]
];

🚀 Usage

Access the PDO instance globally via:

$pdo = database();

Or retrieve it manually from the service container:

$pdo = app()->container()->get(Database::class);

Use it as usual with native PDO:

$stmt = database()->prepare('SELECT * FROM users WHERE id = ?');
$stmt->execute([$id]);
$user = $stmt->fetch(); // default: FETCH_ASSOC

⚙️ Defaults applied

The PDO instance comes with these options:

[
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]

🔍 Internals

  • Loads config from /app/config.php from the key database
  • Builds DSN based on a given driver (mysql, sqlite)
  • Wraps PDO creation in a factory, handles exceptions gracefully
  • Registers database in the container and provides the database() helper

✅ Requirements

  • nixphp/framework >= 0.1.0

📄 License

MIT License.