MeekroDB Quick Start Docs ORM Docs FAQ
Download GitHub

Saving, Updating, and Deleting

Save()

If the record is new, it will be INSERTed. Otherwise, any fields you've changed will be UPDATEd.

$Account = new Account();
$Account->email = '[email protected]';
$Account->password = 'kixbaq!';
$Account->Save();

If any errors prevent the record from being saved, an exception will be thrown.

Update()

For an existing record, update one or more fields and immediately save them.

$Account = Account::Load(1); // load by primary key
$Account->email = '[email protected]';

// UPDATE the password in the database, but the email change above
// will remain un-saved
$Account->update(['password' => 'abcde']);

Destroy()

DELETE an existing record from the database.

$Account = Account::Load(1);
$Account->Destroy();

Reload()

Reload a record from the database. It will pull in any changes made elsewhere, and undo any unsaved changes on our end.

$Account = Account::Load(1);

// change the email?
$Account->email = '[email protected]';

// actually, nevermind!
$Account->reload();