PostgreSQL driver for the Marko framework database layer.
composer require marko/database-pgsqlThis automatically installs marko/database (the interface package) as a dependency.
Create config/database.php with a flat array of connection details:
<?php
declare(strict_types=1);
use Marko\Config\Env;
return [
'driver' => 'pgsql',
'host' => Env::string('DB_HOST', 'localhost'),
'port' => Env::int('DB_PORT', 5432, min: 1, max: 65535),
'database' => Env::string('DB_DATABASE', 'marko'),
'username' => Env::string('DB_USERNAME', 'postgres'),
'password' => Env::string('DB_PASSWORD', ''),
];driver, host, port, database, username, and password are all required. Set the corresponding values in your .env file:
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=marko
DB_USERNAME=postgres
DB_PASSWORD=secretFor multiple connections (for example, read replicas), use marko/database-readwrite, which adds the connections layout.
This driver supports PostgreSQL 14+.
use Marko\Database\Connection\ConnectionInterface;
class MyService
{
public function __construct(
private ConnectionInterface $connection,
) {}
public function doSomething(): void
{
$result = $this->connection->query('SELECT * FROM users');
}
}Full usage, configuration, and API reference: marko/database-pgsql