Skip to content

Repository files navigation

tina4php-orm

Object-relational mapping module for the Tina4 PHP framework, providing a simple ORM that works with any Tina4 database driver.

Installation

composer require tina4stack/tina4php-orm

Requirements

  • PHP >= 8.1

Usage

Defining a Model

use Tina4\ORM;

class User extends ORM
{
    public $primaryKey = "id";
    public $tableName = "users";

    public $id;
    public $firstName;
    public $lastName;
    public $email;
}

Loading and Saving Records

// Load a user by primary key
$user = (new User());
$user->load("id = 1");
echo $user->firstName;

// Create a new user
$user = new User();
$user->firstName = "Alice";
$user->lastName = "Smith";
$user->email = "alice@example.com";
$user->save();

Querying Multiple Records

$users = (new User())->select("*", 10)
    ->filter("active = 1")
    ->orderBy("last_name")
    ->asArray();

Testing

composer test

License

MIT - see LICENSE


Our Sponsors

Sponsored with 🩵 by Code Infinity

Code Infinity

Supporting open source communities Innovate Code Empower

About

ORM for Tina4

Resources

Stars

4 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages