roistat / php-orm
Simple ORM library for PHP
Requires
- php: >=7.4
- ext-pdo: *
Requires (Dev)
- phpunit/phpunit: ^9
This package is not auto-updated.
Last update: 2024-11-10 06:38:42 UTC
README
Overview
It is simple ORM library for PHP. This library is compatible with PHP 5.4 and higher. There are no magic methods. All code is type-hinted. It could be used in high load projects even with partitioning and sharding. There are 3 basic parts (packages). You could combine them or use some of them separately.
- State package — responsible for object state management. Prepares data for usage in DB queries.
- Query package — query builder. It could use data from State package or any other sources.
- Driver package — sends queries to database and parses results.
Installation
composer require roistat/php-orm:dev-master
Or you can't just copy content of ./src
to your src/RsORM
folder with standard namespaces autoload.
Quick Start
Typically you can combine these 3 packages or use them alone. And at first you should define class of entity you work with. This class structure convenient to build accordingly with DB table structure.
class Account extends State\Entity { public $id; public $email; public $password; }
Then you can build MySQL query. For example, select statement.
$statement = Query\Engine\MySQL\Builder::select() ->table("accounts") ->build();
And then you can execute this statement and get result (array of defined class objects).
$mysql = new Driver\MySQL(); $accounts = $mysql->fetchAllClass($statement, "Account"); /* $accounts - array of Account objects, like this: [ {id: 1, email: "qwe@qwe.qwe", password: "123456"}, {id: 2, email: "asd@asd.asd", password: "654321"}, ... ] */
It is simple example of usage RsORM. More detailed information you can find in the relevant sections.
Documentation
State package
Query package
Driver package
License
Released under the MIT License.