GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - riverside/php-orm: :dolphin: PHP micro-ORM and query builder

BranchesTags
Open more actions menu

Latest commit

 

History

75 Commits
75 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
docs
docs
 
 
src
src
 
 
tests
tests
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

Repository files navigation

php-orm

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.1"
    }
}

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' => '[email protected]']);
$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

  • DB
  • Expression
  • Configuration
  • Connection

About

🐬 PHP micro-ORM and query builder

riverside.github.io/php-orm/

Topics

db-wrappermicro-ormmysqlormpdopdo-mysqlpdo-sqlitephpphp-pdoquery-buildersqlitesqlite3

Resources

Readme
MIT license
Activity

Stars

11 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.