Getting Started
Miko ORM is a PHP ORM Framework with fluent query syntax.
Installation
Include Miko ORM in your project by requiring the autoload.php file:
require_once 'Miko/autoload.php';
autoload.php loads Core, DB, QueryBuilder, Logger, cache, library, all drivers, migrations, ORM, seeders, factories, monitors, Database/ConnectionPool and DatabaseManager.
Quick Start
1. Define Your Model
use Miko\Database\ORM\Model;
use Miko\Database\ORM\Traits\HasTimestamps;
class User extends Model
{
use HasTimestamps;
protected static string $table = 'users';
protected string $primaryKey = 'Id';
protected array $fillable = ['Name', 'Email', 'Password', 'Role'];
protected array $hidden = ['Password'];
}
2. Configure Database Connection
use Miko\Database\ORM\DbContext;
use Miko\Database\ORM\MikoSet;
use Miko\Core\Config;
class AppDbContext extends DbContext
{
public MikoSet $Users;
protected function getConfig(): array
{
return [
'host' => Config::env('DB_HOST_LOCAL', 'localhost'),
'port' => (int) Config::env('DB_PORT', 3306),
'database' => Config::env('DB_DATABASE_LOCAL', 'your_database'),
'username' => Config::env('DB_USERNAME_LOCAL', 'root'),
'password' => Config::env('DB_PASSWORD_LOCAL', ''),
'charset' => 'utf8mb4'
];
}
}
$db = new AppDbContext();
$db->ensureCreated();
configure() / setConnection() do not exist on DbContext. Override getConfig(). Public MikoSet properties are discovered automatically (Users → App\Models\User or User).
3. Start Using
// Create
$user = User::create([
'Name' => 'John Doe',
'Email' => 'john@example.com'
]);
// Read
$user = User::find(1);
$users = User::where('IsActive', true)->get();
// Update
$user->Name = 'John Updated';
$user->save();
// Delete
$user->delete();
Supported Databases
| Database | Driver | Default Port |
|---|---|---|
| MySQL / MariaDB | mysql | 3306 |
| PostgreSQL | pgsql | 5432 |
| SQLite | sqlite | - |
| SQL Server | sqlsrv | 1433 |
Project Structure
your-project/
├── Miko/ # library folder (this repo: Miko/Miko)
│ └── autoload.php
├── Log/ # Logger channel files (created at runtime)
├── App/
│ ├── Models/ # Your models
│ │ ├── User.php
│ │ └── Product.php
│ └── DbContext.php # Your database context
└── .env # Environment configuration
Key Features
| Feature | Description |
|---|---|
| Model-First Migration | Auto-create tables from model definitions |
| Fluent Query Builder | Clean query API, including grouped where(function ($q) { ... }) / orWhere(function) |
| Relations | HasOne, HasMany, BelongsTo, BelongsToMany |
| Observers | Model lifecycle events (creating, created, updating, etc.) |
| Bulk Operations | Efficient bulk insert, update, upsert, delete |
| JSON Columns | Native JSON support with dot notation access |
| Validation Attributes | PHP 8 attributes for model validation |
| Connection Pool | Miko\Database\ConnectionPool\ConnectionPool + DatabaseManager for named connections; Miko\Database\ORM\ConnectionPool for a static pool. Set pool.enabled in config. Use session.persistent so PHP-FPM workers reuse PDO handles across requests. |
| Query Cache | Cache query results with tags |
| Soft Deletes | Soft delete support with restore capability |
| Transactions | Transaction support with savepoints |
Next Steps
| Documentation | Description |
|---|---|
| Database Config | Configure your database connection |
| ORM Model | Learn about model definitions |
| Query Builder | Build complex queries |
| Relations | Define model relationships |
| CRUD Examples | Complete CRUD examples |