Skip to content

Latest commit

 

History

History
139 lines (89 loc) · 1.94 KB

File metadata and controls

139 lines (89 loc) · 1.94 KB

PdoDb Methods

Complete reference for PdoDb class methods.

Connection Methods

find(): QueryBuilder

Create new query builder.

$db->find()->from('users')->get();

rawQuery(string $sql, ?array $params = null)

Execute raw SQL query.

$db->rawQuery('SELECT * FROM users WHERE id = ?', [1]);

Transaction Methods

startTransaction(): void

Start transaction.

$db->startTransaction();

commit(): void

Commit transaction.

$db->commit();

rollback(): void

Rollback transaction.

$db->rollback();

transaction(callable $callback)

Execute in transaction.

$result = $db->transaction(function() use ($db) {
    // ...
});

Connection Management

switchConnection(string $name): void

Switch to another connection.

$db->switchConnection('slave');

getConnection(?string $name = null): ConnectionInterface

Get connection instance.

$connection = $db->getConnection();

Query Logging

enableQueryLog(): void

Enable query logging.

$db->enableQueryLog();

disableQueryLog(): void

Disable query logging.

$db->disableQueryLog();

getQueryLog(): array

Get query log.

$log = $db->getQueryLog();

Batch Processing

batch(int $size, callable $callback): void

Process in batches.

$db->batch(100, function($batch) {
    // Process batch
});

each(callable $callback): void

Iterate over results.

$db->find()->from('users')->each(function($user) {
    // Process user
});

stream(): \Generator

Stream query results without loading into memory.

foreach ($db->find()->from('users')->stream() as $user) {
    // Process user
}

Next Steps