Documentation / OmniPHP
Database & models
A fluent query builder and migrations for long-running services.
Worker connections
Configure the database in config/database.php. Run DatabaseBootstrap::init() before worker fork for initialization and migrations, then DatabaseBootstrap::initWorker() in each worker’s onWorkerStart callback. Never share an open connection across fork.
Query builder
Use DB::table to compose queries. MySQL uses the async driver in worker Fibers; SQLite continues to use local PDO.
use OmniPHP\Database\DB;
$books = DB::table('books')
->select('id', 'title')
->where('published', 1)
->orderBy('id', 'DESC')
->limit(20)
->get();Transactions
Keep related writes in a DB::transaction callback. The connection is associated with the transaction for its lifetime.
use OmniPHP\Database\DB;
DB::transaction(function () {
DB::table('books')->where('id', 7)->update([
'published' => 1,
]);
});More database APIs
The repository also documents joins, aggregates, models, migrations and soft deletes.
View framework source ↗