# active-record
**Repository Path**: mirrors_yiisoft/active-record
## Basic Information
- **Project Name**: active-record
- **Description**: Active Record database abstraction layer
- **Primary Language**: Unknown
- **License**: BSD-3-Clause
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-19
- **Last Updated**: 2026-02-07
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
Yii Active Record
[](https://packagist.org/packages/yiisoft/active-record)
[](https://packagist.org/packages/yiisoft/active-record)
[](https://codecov.io/gh/yiisoft/active-record)
[](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/active-record/master)
[](https://github.com/yiisoft/active-record/actions/workflows/static.yml?query=branch%3Amaster)
[](https://shepherd.dev/github/yiisoft/active-record)
[](https://shepherd.dev/github/yiisoft/active-record)
This package provides [Active Record pattern](https://en.wikipedia.org/wiki/Active_record_pattern) implementation.
Supported databases:
| Packages | Build status |
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Microsft SQL Server](https://github.com/yiisoft/db-mssql) | [](https://github.com/yiisoft/active-record/actions/workflows/db-mssql.yml?query=branch%3Amaster) |
| [MySQL](https://github.com/yiisoft/db-mysql) | [](https://github.com/yiisoft/active-record/actions/workflows/db-mysql.yml?query=branch%3Amaster) |
| [Oracle](https://github.com/yiisoft/db-oracle) | [](https://github.com/yiisoft/active-record/actions/workflows/db-oracle.yml?query=branch%3Amaster) |
| [PostgreSQL](https://github.com/yiisoft/db-pgsql) | [](https://github.com/yiisoft/active-record/actions/workflows/db-pgsql.yml?query=branch%3Amaster) |
| [SQLite](https://github.com/yiisoft/db-sqlite) | [](https://github.com/yiisoft/active-record/actions/workflows/db-sqlite.yml?query=branch%3Amaster) |
## Requirements
- PHP 8.1 - 8.5.
## Installation
The package could be installed with [Composer](https://getcomposer.org):
```shell
composer require yiisoft/active-record
```
> [!IMPORTANT]
> See also [installation notes](https://github.com/yiisoft/db/?tab=readme-ov-file#documentation) for `yiisoft/db`
> package.
After installing `yiisoft/active-record`, you also need to configure a database connection:
1. Configure the connection, follow [Yii Database](https://github.com/yiisoft/db/blob/master/docs/guide/en/README.md)
guide.
2. [Define the Database Connection for Active Record](docs/define-connection.md)
## General usage
Defined your active record class (for more information, follow [Create Active Record Model](docs/create-model.md) guide):
```php
final class User extends \Yiisoft\ActiveRecord\ActiveRecord
{
public int $id;
public string $username;
public string $email;
public string $status = 'active';
public function tableName(): string
{
return '{{%user}}';
}
}
```
For fast prototyping you can use dynamic properties by adding `#[\AllowDynamicProperties]` attribute:
```php
/**
* Database fields:
* @property int $id
* @property string $username
* @property string $email
* @property string $status
**/
#[\AllowDynamicProperties]
final class User extends \Yiisoft\ActiveRecord\ActiveRecord
{
}
```
Now you can use the active record:
```php
// Creating a new record
$user = new User();
$user->username = 'alexander-pushkin';
$user->email = 'pushkin@example.com';
$user->save();
// Retrieving a record
$user = User::query()->findByPk(1);
// Read properties
$username = $user->username;
$email = $user->email;
```
## Documentation
- [Define the Database Connection for Active Record](docs/define-connection.md)
- [Create Active Record Model](docs/create-model.md)
- [Define Active Record Relations](docs/define-relations.md)
- [Extending Functionality With Traits](docs/traits/traits.md)
- [Using Dependency Injection With Active Record Model](docs/using-di.md)
- [Optimistic Locking](docs/optimistic-locking.md)
- [Internals](docs/internals.md)
If you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place
for that. You may also check out other [Yii Community Resources](https://www.yiiframework.com/community).
## License
The Yii Active Record is free software. It is released under the terms of the BSD License.
Please see [`LICENSE`](./LICENSE.md) for more information.
Maintained by [Yii Software](https://www.yiiframework.com/).
## Support the project
[](https://opencollective.com/yiisoft)
## Follow updates
[](https://www.yiiframework.com/)
[](https://twitter.com/yiiframework)
[](https://t.me/yii3en)
[](https://www.facebook.com/groups/yiitalk)
[](https://yiiframework.com/go/slack)