承接 riverside/php-orm 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

riverside/php-orm

最新稳定版本:2.0.0

Composer 安装命令:

composer require riverside/php-orm

包简介

PHP ORM micro-library and query builder

README 文档

README

PHP micro-ORM and query builder.

Build GitHub pages Stable License
CI pages-build-deployment Latest Stable Version License

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.

{
    "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:

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
putenv("DEFAULT_USERNAME=your_username");
putenv("DEFAULT_PASSWORD=your_password");
putenv("DEFAULT_DATABASE=your_database");
putenv("DEFAULT_HOST=localhost");
putenv("DEFAULT_PORT=3306");
putenv("DEFAULT_DRIVER=mysql");
putenv("DEFAULT_CHARSET=utf8mb4");
putenv("DEFAULT_COLLATION=utf8mb4_general_ci");

Drivers

The following drivers are supported: mysql, oci, firebird, pgsql, sqlite, sybase, mssql, dblib, cubrid, 4D.

Database

Table: users

Name Type Collation Attributes Null Extra
id int(10) UNSIGNED No AUTO_INCREMENT
name varchar(255) utf8mb4_general_ci Yes
email varchar(255) utf8mb4_general_ci Yes

Models

Define your own models:

<?php
use Riverside\Orm\DB;

class User extends DB
{
    protected $table = 'users';
    
    protected $attributes = ['id', 'name', 'email'];
    
    // protected $connection = 'backup';
    
    public static function factory()
    {
        return new self();
    }
}

Query Builder

  • with model: create an instance of a model using the factory method. Then chain multiple methods. The following is example of simple CRUD:
$id = User::factory()->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
$db = new \Riverside\Orm\DB();
$db->table('users')->get();

API

统计信息

  • 总下载量: 1.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-10-30