Skip to content

Instantly share code, notes, and snippets.

Created August 2, 2013 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/6138847 to your computer and use it in GitHub Desktop.
Save anonymous/6138847 to your computer and use it in GitHub Desktop.
Basic CRUD with PHPActiveREcord
<?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