Repository navigation
Installation
github-actions[bot] edited this page Nov 23, 2026
·
3 revisions
- PHP 8.2 or later — older versions are not supported. The test matrix covers PHP 8.2, 8.3, 8.4 and 8.5.
-
ext-pdo— always required. - A PDO driver matching your target database — one of:
-
ext-pdo_mysql(MySQL / MariaDB) -
ext-pdo_pgsql(PostgreSQL) -
ext-pdo_sqlite(SQLite) - any other PDO driver PHP ships (
pdo_oci,pdo_sqlsrv, …)
-
composer require initphp/databaseTo install a specific major version:
composer require initphp/database:^5.0A two-line smoke test:
<?php
require __DIR__ . '/vendor/autoload.php';
$db = new InitPHP\Database\Database([
'driver' => 'sqlite',
'database' => ':memory:',
'charset' => '',
]);
$db->getPDO()->exec('CREATE TABLE ping (id INTEGER)');
$db->create('ping', ['id' => 1]);
var_dump($db->select('*')->from('ping')->read()->asAssoc()->rows());If you see one row come back, you are good to go.
After install the package exposes four entry points:
| Class | Use case |
|---|---|
InitPHP\Database\DB |
Static facade — bootstrap once with DB::createImmutable([...]) and call DB::select(...) from anywhere. |
InitPHP\Database\Database |
Direct instantiation — when you want to own the lifecycle yourself, e.g. multiple connections. |
InitPHP\Database\Model |
Subclass it to bind one table; pairs with Entity. |
InitPHP\Database\Entity |
Subclass it for typed row objects with accessor / mutator hooks. |
InitPHP\Database\Utils\Datatables\Datatables |
Server-side DataTables.js helper. |
The package ships its own CI pipeline; if you fork or contribute, install the dev dependencies:
composer install
composer qa # php-cs-fixer (dry run) + phpstan + phpunit
composer cs-fix # auto-format| Tool | Config file |
|---|---|
| PHPUnit | phpunit.xml |
| PHPStan (level 6) | phpstan.neon.dist |
| PHP-CS-Fixer (PER-CS) | .php-cs-fixer.dist.php |
- Quick Start — a 10-minute tour.
- Configuration — every supported connection option.
initphp/database · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Core API
ORM
Advanced
DataTables Helper
Recipes
- Index
- — Pagination
- — Search & Filters
- — Upsert / REPLACE INTO
- — Audit Log
- — DataTables Bootstrap
- — Repository Pattern
Reference
Migration & Help