https://github.com/riverside/php-orm
:dolphin: PHP micro-ORM and query builder
https://github.com/riverside/php-orm
db-wrapper micro-orm mysql orm pdo pdo-mysql pdo-sqlite php php-pdo query-builder sqlite sqlite3
Last synced: 5 months ago
JSON representation
:dolphin: PHP micro-ORM and query builder
- Host: GitHub
- URL: https://github.com/riverside/php-orm
- Owner: riverside
- License: mit
- Created: 2020-10-26T17:48:20.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-09-14T17:08:28.000Z (over 1 year ago)
- Last Synced: 2025-08-29T11:19:41.833Z (5 months ago)
- Topics: db-wrapper, micro-orm, mysql, orm, pdo, pdo-mysql, pdo-sqlite, php, php-pdo, query-builder, sqlite, sqlite3
- Language: PHP
- Homepage: https://riverside.github.io/php-orm/
- Size: 685 KB
- Stars: 11
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# php-orm
PHP micro-ORM and query builder.
| Build | GitHub pages | Stable | License |
| ----- | ------------ | ------ | ------- |
| [![CI][x1]][y1] | [![pages-build-deployment][x4]][y4] | [![Latest Stable Version][x2]][y2] | [![License][x3]][y3] |
### Requirements
- PHP >= 7.1
- PHP extensions:
- PDO (`ext-pdo`)
### Installation
If Composer is not installed on your system yet, you may go ahead and install it using this command line:
```
$ curl -sS https://getcomposer.org/installer | php
```
Next, add the following require entry to the composer.json file in the root of your project.
```json
{
"require" : {
"riverside/php-orm" : "^2.0"
}
}
```
Finally, use Composer to install php-orm and its dependencies:
```
$ php composer.phar install
```
### Configuration
Include autoload in your project:
```php
require __DIR__ . '/vendor/autoload.php';
```
Configure database credentials by setting up the following environment variables:
`USERNAME`, `PASSWORD`, `DATABASE`, `HOST`, `PORT`, `DRIVER`, `CHARSET`, `COLLATION`. They must be
prefixed with `$connection` property value, part of your model, in capital letters and underscore. The default value of `$connection`
property is 'default'. For example:
```php
insert(['name' => 'Chris', 'email' => 'chris@aol.com']);
$user = User::factory()->where('id', $id)->get();
$affected_rows = User::factory()->where('id', $id)->update(['name' => 'Chris Johnson']);
$affected_rows = User::factory()->where('id', $id)->delete();
```
- without model: create a new instance of `Riverside\Orm\DB` class
```php
$db = new \Riverside\Orm\DB();
$db->table('users')->get();
```
### API
- [DB][1]
- [Expression][2]
- [Configuration][3]
- [Connection][4]
[1]: https://riverside.github.io/php-orm/api.html#db
[2]: https://riverside.github.io/php-orm/api.html#expr
[3]: https://riverside.github.io/php-orm/api.html#cfg
[4]: https://riverside.github.io/php-orm/api.html#con
[x1]: https://github.com/riverside/php-orm/actions/workflows/test.yml/badge.svg
[y1]: https://github.com/riverside/php-orm/actions/workflows/test.yml
[x2]: https://poser.pugx.org/riverside/php-orm/v/stable
[y2]: https://packagist.org/packages/riverside/php-orm
[x3]: https://poser.pugx.org/riverside/php-orm/license
[y3]: https://packagist.org/packages/riverside/php-orm
[x4]: https://github.com/riverside/php-orm/actions/workflows/pages/pages-build-deployment/badge.svg
[y4]: https://github.com/riverside/php-orm/actions/workflows/pages/pages-build-deployment