Created
August 2, 2013 10:12
-
-
Save anonymous/6138847 to your computer and use it in GitHub Desktop.
Basic CRUD with PHPActiveREcord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class User extends \Activerecord\Model | |
{ | |
//nothing more to do here | |
} | |
$attributes = array( | |
'name' => 'nuita', | |
'password' => md5('password'), | |
'created' => new \DateTime(), | |
); | |
// Create | |
$user = User::create($attributes); | |
printf("we have created a new user %s here's his ID : %d <br />", $user->name, $user->id); | |
// Read | |
$user = User::find(1); | |
$attributes = $user->attributes(); | |
foreach ($attributes as $column => $value) { | |
printf("%s : %s <br />", $column, $value); | |
} | |
// Update | |
$user = User::find(1); | |
$user->last_seen = new \DateTime(); | |
$user->save(); | |
// Delete | |
$user = User::find(1); | |
$user->delete(); | |
printf("user %s no longer exist in our database <br />", $user->name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment