dev-master
9999999-devDatabase abstraction layer and ORM
MIT
The Requires
- php >=7.0
- ext-pcre *
- phore/cli ^1.0
The Development Requires
by Marius
Wallogit.com
2017 © Pedro Peláez
Database abstraction layer and ORM
Phore-dba is a very simple Object-Relational Mapper for PHP 7., (*1)
It will map Objects to Tables using exact the same Names., (*2)
Install using composer:, (*3)
composer require phore/dba
SomeEntity and define __META__ data/path/to/sqlite.db3
SomeEntity
name: someName and company: SomeCompany
query() all Entities and map them back to Entity using each(callable $fn)
update() each entity, then delete() it (hm - it's just a demo)class SomeEntity {
use Entity;
const __META__ = [ "primaryKey" => "id" ];
public $id;
public $name;
public $company;
}
$odb = PhoreDba::InitDSN("sqlite:/path/to/sqlite.db3");
// Use multi_query() to execute multiple Statements
$odb->multi_query ("CREATE TABLE IF NOT EXISTS SomeEntity (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
company TEXT
);");
$odb->insert(new SomeEntity(["name"=>"someName", "company"=>"SomeCompany"]));
$odb->query("SELECT * FROM SomeEntity WHERE name=?", ["UnescapedValue"])->each(
function (array $row) use ($odb) {
print_r ($entity = SomeEntity::Load($row["id"]);
$entity->name = "MyNewName";
$odb->update($entity);
$odb->delete($entity);
}
);
$entity = $odb->load(SomeEntity::class, 103878);
or - with object casting (IDE Code-Completion):, (*4)
$entity = SomeEntity::Load(103878);
Entities must be loaded calling the load() method, so the framework
can track changes. You should use query() only to retrieve Id's and
load the entities afterwards., (*5)
$entity = SomeEntity::Load(1234); // Shortcut
$entity->name = "new Name";
assert ($enetity->isChanged("name") === true)
Database abstraction layer and ORM
MIT