Skip to main content

Introduction

Lyger provides a powerful database layer inspired by Laravel’s Eloquent ORM and Query Builder. It supports multiple database drivers including SQLite, PostgreSQL, MySQL, and MariaDB, making it easy to work with databases in your PHP applications.

Database Configuration

Database configuration is managed through environment variables in your .env file.
SQLite is the default database driver and requires no additional setup.
.env
SQLite is perfect for development and small applications. The database file will be automatically created in the database/ directory.

Database Structure

Lyger automatically creates and manages your database directory structure:

Quick Example

Here’s a quick example to get you started with database operations:
1

Create a Model

Create a model class that extends Lyger\Database\Model:
app/Models/User.php
2

Query the Database

Use the model to interact with your database:
3

Update and Delete

Modify existing records:

Database Connection

The database connection is automatically managed by Lyger. The framework handles:
  • Connection pooling
  • Error handling with exceptions
  • PDO attribute configuration
  • Automatic directory creation

Manual Connection Access

If you need direct PDO access, you can get it through the QueryBuilder:
Manual PDO access should be used sparingly. The Query Builder and Eloquent ORM provide safer, more convenient methods for most use cases.

Error Handling

Lyger uses PDO exceptions for database errors:

Next Steps

Query Builder

Learn about the fluent Query Builder interface

Eloquent Models

Explore the Eloquent ORM features

Migrations

Manage your database schema with migrations

Relationships

Define relationships between models