Skip to main content

Database Configuration (config/database.php)

The database.php file defines available database connections and the default one your application should use.

๐Ÿ”ง Default Connectionโ€‹

'default' => env('DB_CONNECTION', 'pgsql'),

This value can be switched using the DB_CONNECTION environment variable.

๐Ÿ›  Supported Driversโ€‹

  • pgsql (PostgreSQL)
  • mysql
  • sqlite
  • sqlsrv

Each driver can be configured using its own env-based options:

'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', 5432),
'database' => env('DB_DATABASE', 'app'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', 'secret'),
'charset' => 'utf8',
],

๐Ÿงช Usage Exampleโ€‹

use Beauty\Database\Connection\ConnectionInterface;

$db = container()->get(ConnectionInterface::class);

$results = $db->select("SELECT * FROM users WHERE active = ?", [true]);