PHP micro-ORM and query builder.
Build | GitHub pages | Stable | License |
---|---|---|---|
- PHP >= 7.1
- PHP extensions:
- PDO (
ext-pdo
)
- PDO (
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.
{
"require" : {
"riverside/php-orm" : "*"
}
}
Finally, use Composer to install php-orm and its dependencies:
$ php composer.phar install
Include autoload in your project:
require __DIR__ . '/vendor/autoload.php';
Define path to configuration file:
DB::config('config/database.php');
config/database.php
<?php
return array(
'default' => array(
'driver' => 'mysql',
'host' => 'localhost',
'port' => 3306,
'username' => 'root',
'password' => 'secret',
'database' => 'test',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
),
);
Table: users
Name | Type | Collation | Attributes | Null | Extra |
---|---|---|---|---|---|
id | int(10) | UNSIGNED | No | AUTO_INCREMENT | |
name | varchar(255) | utf8mb4_general_ci | Yes | ||
varchar(255) | utf8mb4_general_ci | Yes |
Define your own models:
<?php
use PhpOrm\DB;
class User extends DB
{
protected $table = 'users';
protected $attributes = ['id', 'name', 'email'];
// protected $connection = 'backup';
public static function factory()
{
return new self();
}
}
- with model:
create an instance of a model using the
factory
method. Then chain multiple methods.
User::factory()->get();
- without model: create a new instance of
PhpOrm\DB
class
$db = new \PhpOrm\DB();
$db->table('users')->get();