Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Installation
Muhammet Şafak edited this page May 24, 2026
·
1 revision
- PHP 8.1 or later — older versions are not supported. The 4.x line technically declared
>= 8.0but its transitive dependencies refused to install on PHP 8.0, so 8.1 is now the floor. 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:
<?phprequire__DIR__ . '/vendor/autoload.php';
$db = newInitPHP\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 # phpcs + phpstan + phpunit
composer cs-fix # auto-format| Tool | Config file |
|---|---|
| PHPUnit | phpunit.xml |
| PHPStan (level 6) | phpstan.neon.dist |
| PHP_CodeSniffer (PSR-12) | phpcs.xml.dist |
- 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