Skip to content

Swoole runtime and connection drivers

MySQL

Core 2.5 and newer uses native PDO because Swoole 6 removed Swoole\Coroutine\MySQL.

Required connection keys:

[
    'type' => 'mysql',
    'host' => 'mysql',
    'port' => '3306',
    'database' => 'app',
    'user' => 'app',
    'password' => 'secret',
    'encoding' => 'utf8mb4',
    'maxConnections' => 50,
]

Enable Swoole runtime hooks before database I/O. Never share a checked-out PDO connection between coroutines.

PostgreSQL

[
    'type' => 'postgres',
    'host' => 'postgres',
    'port' => '5432',
    'database' => 'app',
    'user' => 'app',
    'password' => 'secret',
    'encoding' => 'UTF8',
    'maxConnections' => 100,
]

The PostgreSQL connection uses pooled PgSql\Connection instances. Named parameters are rewritten by the driver adapter.

Small Swoole DB

[
    'type' => 'swoole-db',
]

This driver uses small/swoole-db and Swoole tables. It supports the relational query builders and persistence threads, but not every SQL database feature.

Raw statements

Connections accept driver-native statement objects rather than plain SQL strings.

use Small\Collection\Collection\Collection;
use Small\SwooleEntityManager\Database\Connection\Mysql\Bean\SqlStatement;

$statement = new SqlStatement(
    'SELECT * FROM users WHERE id = :id',
    new Collection(['id' => 42]),
);

$result = $connectionFactory->get()->execute($statement);

Use the statement class matching the configured driver.