Skip to content
Muhammet Şafak edited this page May 24, 2026 · 7 revisions

InitPHP Database — Wiki

Welcome to the official documentation for initphp/database — a Composer-friendly database facade for PHP 8.1+. It bundles a fluent query builder, a DBAL connection layer, an active-record-style ORM with soft deletes and timestamp columns, and a server-side DataTables.js helper.

composer require initphp/database
useInitPHP\Database\DB;
DB::createImmutable([
'dsn' => 'mysql:host=localhost;port=3306;dbname=test;charset=utf8mb4',
'username' => 'root',
'password' => '',
]);
$rows = DB::select('id', 'title')
->from('posts')
->where('status', 1)
->orderBy('id', 'DESC')
->limit(10)
->read()
->asAssoc()
->rows();

The package re-exports the InitORM stack under the InitPHP\Database namespace and ships one piece of original code on top — the DataTables helper.

LayerClass / FacadePurpose
FacadeInitPHP\Database\DBStatic entry point over a shared Database instance
DBALInitPHP\Database\DatabaseConnection + builder + CRUD orchestration
ORMInitPHP\Database\ModelActive-record table binding with soft deletes
ORMInitPHP\Database\EntityAttribute bag with accessor / mutator hooks
UtilityInitPHP\Database\Utils\Datatables\DatatablesServer-side DataTables.js integration

Start here

Feature matrix

CapabilityStatus
Fluent SELECT / WHERE / JOIN / GROUP BY / HAVING / ORDER BY / LIMIT
Insert / Update / Delete + batch variants (createBatch, updateBatch)
Prepared statements with automatic parameter binding
Driver-specific identifier escaping (backticks on MySQL/SQLite, "…" on PostgreSQL)
Soft deletes (deleted_at) and auto-managed created_at / updated_at columns
Per-model access gates ($readable, $writable, $updatable, $deletable)
Entity accessor / mutator hooks (Laravel-style get{Col}Attribute / set{Col}Attribute)
Dirty tracking via getOriginal() / syncOriginal()
Transactions with retry count and testMode (always rolls back)
In-memory query log (enableQueryLog / getQueryLogs)
Connection-level log channel — file path, callable, PSR-3 logger, or object with critical()
debug=true to surface compiled SQL in error messages
Multiple connections (DB::connect() and Model::$credentials)
Server-side DataTables.js (search / sort / paging / per-column renderers / group-by counts)

Package metadata

If a page is unclear, ambiguous, or wrong, please open an issue — documentation fixes ship eagerly.

Clone this wiki locally