Fwk\Db tries to mimic a database ORM (Object Relational Mapper) without carrying all its complexity and (finally) let the developer enjoy CRUD operations, object-oriented entities and relations without configuring anything.
- Per-query Models: Switch from an Entity to another depending on what's needed.
- No Entity required at all:
stdClass
is minimalist's best friend. - No new SQL language: use a clean Object-oriented Query API or just SQL itself.
- Event-Driven Engine: Intercept any Event and customize the behavior the way you like. Even on
stdClass
Models. - Proven Foundation: Built on top of the famous DataBase Abstraction Layer by the Doctrine Project (DBAL).
First, we initialize the database connection object:
use Fwk\Db\Connection;
$db = new Connection(array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'username',
'password' => 'passwd',
'dbname' => 'example'
));
Create a new object:
$user = (object)array(
'id' => null,
'username' => 'neiluJ',
'email' => '[email protected]',
'password' => 'abcdef'
);
$db->table('users')->save($user); // INSERT INTO users ...
Read table:
$user = $db->table('users')->finder()->one(1); // SELECT * FROM users WHERE id = 1
Update table:
$user->password = 'changed password';
$db->table('users')->save($user); // UPDATE users SET ... WHERE id = 1
Delete from table:
$db->table('users')->delete($user); // DELETE FROM users WHERE id = 1