Skip to content

Latest commit

 

History

History

docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Fwk\Db Documentation

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.

Features

Examples

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'
));

Basic CRUD

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

View more exemples here.