pavlyshyn / orm
0.2.4
2016-07-21 22:09 UTC
Requires
- php: >=5.3.0
- pavlyshyn/annotation: 0.1.*
This package is auto-updated.
Last update: 2024-11-27 01:36:35 UTC
README
use Pavlyshyn\Orm; use Pavlyshyn\DB\Driver\MySQL; use Model\User; $orm = new Orm(new MySQL('localhost', 'test_orm', 'root', 'password')); OR use Pavlyshyn\DB\Driver\MongoDB; $orm = new Orm(new MongoDB('localhost', 'test_orm'));
<?php namespace Model; use \Pavlyshyn\Model; /** * @tableName users */ class User extends Model { protected $id; protected $name; protected $mail; protected $password; public function setId($id) { return $this->id = $id; } public function getId() { return $this->id; } public function setName($name) { return $this->name = $name; } public function getName() { return $this->name; } public function setMail($mail) { return $this->mail = $mail; } public function getMail() { return $this->mail; } public function setPassword($password) { return $this->password = $password; } public function getPassword() { return $this->password; } }
######INSERT
$user = new User(); $user->name = 'Username'; $user->mail = 'username@mail.com'; $user->password = sha1('password'); $orm->save($user);
######UPDATE
//get user $user = new User(); $user->id = 1; $user = $orm->get($user); //update $user->password = sha1('new password'); $orm->save($user);
######GET
$users = new User(); $tabUsers = $orm->getAll($users); var_dump($tabUsers); foreach($tabUsers as $user){ echo 'Name : ' . $user->name . '<br>'; echo 'Email : ' . $user->mail . '<br>'; echo 'Password : ' . $user->password . '<br>'; }
######DELETE BY ID
$users = new User(); $user->id = 1; $orm->deleteById($users);
######DELETE (PARAMETERS $OBJECT, $ROWNAME AND $VALUE)
$users = new User(); $orm->delete($users, 'name', 'Username');
######COUNT
$users = new User(); $count = $orm->count($users); var_dump($count);
######EXIST (PARAMETERS $OBJECT, $ROWNAME AND $VALUE)
$users = new User(); $res = $orm->exist($users, 'name', 'Username'); var_dump($res);