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

InitORM Database — Wiki

initorm/database is the glue layer of the InitORM stack. It composes the connection layer (initorm/dbal) and the fluent query builder (initorm/query-builder) into a single, fluent Database manager with:

  • CRUD helperscreate, createBatch, read, update, updateBatch, delete
  • Transactions with retry + testMode
  • Query log profiler for finding N+1 problems and slow queries
  • Optional static facade (DB::…) for application code that doesn't need DI
useInitORM\Database\Facade\DB;
DB::createImmutable([
'dsn' => 'mysql:host=localhost;dbname=app;charset=utf8mb4',
'username' => 'app',
'password' => 'secret',
]);
$users = DB::select('id', 'name')
->where('active', '=', 1)
->orderBy('id', 'DESC')
->limit(10)
->read('users')
->asAssoc()
->rows();

How to read this wiki

If you are brand new:

  1. Installation — install and pick your driver
  2. Getting Started — first ten minutes
  3. Configuration — every credential, explained

If you have a specific question:

QuestionPage
"How do I run an INSERT/UPDATE/DELETE?"CRUD Operations
"How do I build a SELECT with joins?"Query Builder
"How do I execute raw SQL?"Raw Queries
"How do I commit/rollback?"Transactions
"How do I use the static facade safely?"Static Facade
"Can I use multiple databases?"Multiple Connections
"How do I log slow queries?"Query Profiler
"How do I route failures to Monolog?"Logging and Debug
"How does the __call magic work?"Architecture
"How do I paginate / chunk / bulk insert?"Recipes
"Is X possible? Why does Y throw?"FAQ

If you are upgrading:

If you are contributing:

What this package is not

  • Not an ORM. Models, hooks, accessors/mutators live in initorm/orm.
  • Not a migration tool, schema dumper, or fixture loader.
  • Not a connection pool. PHP's request lifecycle handles that; persistent connections live in options[PDO::ATTR_PERSISTENT].
  • Not a query builder by itself. That's initorm/query-builder; this package exposes its full surface through __call.

The InitORM stack at a glance

┌────────────────────────────────────────────────────────┐
│ initorm/orm ← active-record models, hooks │
├────────────────────────────────────────────────────────┤
│ initorm/database ← ★ you are here │
│ CRUD + transactions + facade │
├────────────────────┬───────────────────────────────────┤
│ initorm/dbal │ initorm/query-builder │
│ Connection (PDO) │ QueryBuilder (SQL assembly) │
│ DataMapper │ Compilers (string-join) │
└────────────────────┴───────────────────────────────────┘

Pick any layer — they don't force you to use the one above.

Package status

Clone this wiki locally