Environment Variables
The simplest way to configure your database is through the.env file:
Connection String Formats
DatabaseConfig
For programmatic configuration, useDatabaseConfig:
Builder Pattern
You can also build configuration manually:Connection Pooling
Kit automatically manages a connection pool for optimal performance. Configure pooling settings throughDatabaseConfig:
Database Initialization
The database is automatically initialized when your Kit application starts. TheDB::init() method is called during bootstrap:
Manual Initialization
If you need to initialize the database manually:Accessing the Connection
Use theDB facade to access the database connection anywhere in your application:
Multiple Databases
For applications requiring multiple database connections, you can manage connections manually:Environment-Specific Configuration
Use different configurations for development, testing, and production:Troubleshooting
Connection Refused
If you see connection refused errors:- Verify the database server is running
- Check the connection string format
- Ensure network access (firewall, security groups)
Pool Exhausted
If connections are being exhausted:- Increase
max_connections - Ensure connections are being released (avoid long-running transactions)
- Check for connection leaks in your code