Skip to content

API Reference

Muhammet Şafak edited this page May 24, 2026 · 1 revision

API Reference

A flat index of the public surface — every method, grouped by class. Topical guides on the rest of the wiki link in here when you need a quick lookup.

InitPHP\Database\DB — static facade

MethodSignature
createImmutablestatic createImmutable(array|ConnectionInterface $connection): DatabaseInterface — throws if a shared instance is already set
replaceImmutablestatic replaceImmutable(array|ConnectionInterface|DatabaseInterface|null $connection): ?DatabaseInterface
connectstatic connect(array|ConnectionInterface $connection): DatabaseInterface — does not touch the facade slot
getDatabasestatic getDatabase(): DatabaseInterface — throws if none configured
__callStaticForwards every other call to the shared Database

The constructor is private — DB cannot be instantiated.

InitPHP\Database\Database — extends InitORM\Database\Database

CRUD

MethodSignature
createcreate(?string $table = null, ?array $set = null): bool
createBatchcreateBatch(?string $table = null, ?array $set = null): bool
readread(?string $table = null, ?array $selectors = null, ?array $conditions = null): DataMapperInterface
updateupdate(?string $table = null, ?array $set = null, ?array $conditions = null): bool
updateBatchupdateBatch(string $referenceColumn, ?string $table = null, ?array $set = null, ?array $conditions = null): bool
deletedelete(?string $table = null, ?array $conditions = null): bool

Raw and metadata

MethodSignature
queryquery(string $sqlQuery, ?array $parameters = null, ?array $options = null): DataMapperInterface
getConnectiongetConnection(): ConnectionInterface
getPDOgetPDO(): PDO
insertIdinsertId(): string|false
affectedRowsaffectedRows(): int

Transactions

MethodSignature
transactiontransaction(Closure $closure, int $attempt = 1, bool $testMode = false): bool

Builder lifecycle

MethodSignature
withFreshBuilderwithFreshBuilder(): DatabaseInterface — fresh builder, same connection
builderbuilder(): DatabaseInterfacedeprecated alias of withFreshBuilder

Query log

MethodSignature
enableQueryLogenableQueryLog(): static
disableQueryLogdisableQueryLog(): static
getQueryLogsgetQueryLogs(): array<int, array{query: string, args: array, timer: float}>

Query Builder surface (via __call)

Every call below returns $this (chainable) unless noted otherwise. The full list is reproduced in InitORM\Database\Facade\DB as @method static …. The most useful slice:

SELECT clauses

MethodNotes
select(string|RawQuery ...$columns)Variadic column list.
clearSelect()Reset the projection.
selectCount, selectCountDistinct, selectSum, selectAvg, selectMax, selectMinAggregates.
selectUpper, selectLower, selectLengthString functions.
selectMid, selectLeft, selectRightSubstring helpers.
selectConcat(array $columns, ?string $alias = null)CONCAT(...).
selectCoalesceCOALESCE(col, default).
selectDistinctDISTINCT col.
selectAs($column, string $alias)Explicit alias.

FROM / JOIN

MethodNotes
from($table, ?$alias = null)
addFrom($table, ?$alias = null)Comma-joined extra FROM.
table($table)Alias for from.
join($table, $onStmt = null, string $type = 'INNER')
innerJoin, leftJoin, rightJoin, leftOuterJoin, rightOuterJoin
selfJoin($table, $onStmt)
naturalJoin($table)
on($col, $op = '=', $val = null, string $logical = 'AND')Inside a join closure.

WHERE

MethodNotes
where($col, $op = '=', $val = null, string $logical = 'AND')Operator defaults to =.
andWhere, orWhereSame args without the logical.
whereIn, whereNotIn, andWhereIn, orWhereIn, andWhereNotIn, orWhereNotIn
whereIsNull, whereIsNotNull, andWhereIsNull, orWhereIsNull, andWhereIsNotNull, orWhereIsNotNull
between($col, $first, $last, $logical = 'AND') + not/and/or variants
like($col, $val, string $type = 'both', string $logical = 'AND') + or/and/notLikeType: both/before/after.
startLike, endLike + or/and and not variants
findInSet + variantsMySQL FIND_IN_SET.
regexp($col, string $val, string $logical = 'AND') + variants
soundex + variants

GROUP BY / HAVING

MethodNotes
groupBy($col, ...)Variadic.
having($col, $op = '=', $val = null, string $logical = 'AND')

ORDER / LIMIT

MethodNotes
orderBy($col, string $dir = 'ASC')
offset(int $offset = 0)
limit(int $limit)

Composition

MethodNotes
group(Closure $closure, string $logical = 'AND')Parenthesised sub-clause. Caveat: parameter binding inside the closure is broken in initorm/query-builder 2.x — see Query Builder.
subQuery(Closure $closure, ?string $alias = null, bool $isIntervalQuery = true): RawQuery
raw(mixed $rawQuery): RawQuery

Parameter bag

MethodNotes
getParameter(): ParameterInterfaceAccess the underlying bag.
setParameter(string $key, mixed $value)Single binding.
setParameters(array $parameters = [])Batch binding.

SET (used inside the chain by create / update)

MethodNotes
set($col, mixed $value = null, bool $strict = true)One column.
addSet($col, mixed $value = null, bool $strict = true)Append.

InitPHP\Database\Model — extends InitORM\ORM\Model

Configuration properties

PropertyDefaultPurpose
protected string $schemaderived from class short nameTable name.
protected string $schemaId'id'Primary key column.
protected string $entityInitPHP\Database\Entity::classClass used by read() to hydrate.
protected bool $useSoftDeletesfalseEnable soft-delete behaviour.
protected ?string $deletedFieldnullRequired when useSoftDeletes = true.
protected ?string $createdFieldnullAuto-fill on insert.
protected ?string $updatedFieldnullAuto-fill on update.
protected string $timestampFormat'Y-m-d H:i:s'date() format.
protected bool $readabletrueGate on read().
protected bool $writabletrueGate on create() / createBatch().
protected bool $updatabletrueGate on update() / updateBatch().
protected bool $deletabletrueGate on delete().
protected ?array $credentialsnullNon-shared connection.

Methods

MethodSignature
getSchemagetSchema(): string
getSchemaIdgetSchemaId(): string
getDatabasegetDatabase(): DatabaseInterface
createcreate(array $set = []): bool
createBatchcreateBatch(array $set = []): bool
readread(array $selector = [], array $conditions = []): DataMapperInterface
updateupdate(array $set = [], ?array $conditions = null): bool
updateBatchupdateBatch(array $set = [], ?string $referenceColumn = null): bool
deletedelete(?array $conditions = null, bool $purge = false): bool
savesave(EntityInterface $entity): bool — insert-or-update by primary key
onlyDeletedonlyDeleted(): static — one-shot scope flag
ignoreDeletedignoreDeleted(): static — append IS NULL predicate

Exceptions thrown

GateException
$readable = falseInitORM\ORM\Exceptions\ReadableException
$writable = falseInitORM\ORM\Exceptions\WritableException
$updatable = falseInitORM\ORM\Exceptions\UpdatableException
$deletable = falseInitORM\ORM\Exceptions\DeletableException
$useSoftDeletes = true but $deletedField is emptyInitORM\ORM\Exceptions\ModelException (in constructor)

InitPHP\Database\Entity — extends InitORM\ORM\Entity

Methods

MethodSignature
__construct__construct(?array $data = []) — runs every key through __set (so mutators fire).
__get__get(string $name): mixed — dispatches to get{Column}Attribute accessor when defined.
__set__set(string $name, mixed $value): void — dispatches to set{Column}Attribute mutator when defined.
__isset__isset(string $name): bool
__unset__unset(string $name): void
__debugInfoReturns the attribute bag — for var_dump.
toArraytoArray(): array
getAttributesgetAttributes(): array
getOriginalgetOriginal(): array — construct-time snapshot.
getAttributegetAttribute(string $name): mixed
setAttributesetAttribute(string $name, mixed $value): staticuse this from mutator bodies.
syncOriginalsyncOriginal(): static — refresh the snapshot.

InitPHP\Database\Utils\Datatables\Datatables

MethodSignature
__construct__construct(DatabaseInterface|ModelInterface $db, ?RequestParser $request = null, ?Renderer $renderer = null)
__callCaptures any builder method for replay. Returns $this.
__toString(string) $dt — JSON envelope ({} on failure).
toArraytoArray(): array{draw, recordsTotal, recordsFiltered, data, post}
handlehandle(): self — runs the three queries and populates toArray()'s payload.
setColumnssetColumns(?string ...$columns): self — append.
addRenderaddRender(string $column, Closure $render): self
addPermanentSelectaddPermanentSelect(string ...$select): self
orderBySaveorderBySave(): self — keep captured orders alongside the client's.

InitPHP\Database\Utils\Datatables\RequestParser

MethodSignature
__construct__construct(array $payload)
fromGlobalsstatic fromGlobals(): self — merges $_GET, $_POST, php://input JSON.
allall(): array
drawdraw(): int
startstart(): int — clamped to ≥ 0.
lengthlength(): int — returns -1 when "all rows".
hasPaginationhasPagination(): bool
searchValuesearchValue(): ?string
ordersorders(): list<array{0: int, 1: 'ASC'|'DESC'}>

InitPHP\Database\Utils\Datatables\Renderer

MethodSignature
addadd(string $column, Closure $render): void
hasAnyhasAny(): bool
applyapply(array $rows): array

InitORM\DBAL\DataMapper\Interfaces\DataMapperInterface

Returned by read() / query().

MethodSignature
asAssocasAssoc(): self
asObjectasObject(?object $obj = null): self
asClassasClass(?string $class = null): self
asLazyasLazy(): self
asArrayasArray(): self
asBothasBoth(): self — alias of asArray.
rowrow(): array|object|null
rowsrows(): array<int, array|object>
numRowsnumRows(): intunreliable for SELECT on SQLite / unbuffered MySQL.
executeexecute(?array $params = null): bool
getStatementgetStatement(): PDOStatement
getQuerygetQuery(): string
bind, bindValue, bindValuesParameter binding primitives.

Plus @mixin PDOStatement — every native PDOStatement method is forwarded through.

Clone this wiki locally