MeekroDB Quick Start Docs ORM Docs FAQ
Download GitHub

Loading and Searching

Load()

Most tables have a single primary key. In those cases, you can load it like this:

$Account = Account::Load($primary_key);

A primary key can also span multiple columns. In that case, it works the same way:

$Account = Account::Load($key1, $key2);

If no records match, returns null.

Search()

Returns a single object matching the given query. For simple queries with one or more key=value matches, you can do this:

$Account = Account::Search(['email' => $email, 'is_approved' => 1]);

For more complicated search queries, you can write your own query just like you would with MeekroDB's query(). It's always a good idea to add LIMIT 1 to your query, since you'll only get back one object anyway.

$Account = Account::Search("SELECT * FROM accounts WHERE id>%i AND created_at>DATE_SUB(NOW(), INTERVAL 1 YEAR) LIMIT 1", 100);

You can even add "virtual columns" in your MySQL query, which will be available as properties on the object. Needless to say, any changes to these will not be saved.

$Account = Account::Search("SELECT *, REVERSE(email) AS email_backwards FROM accounts WHERE id=%i", 50);
echo "The email address backwards is {$Account->email_backwards}\n";

Always returns a single object. If there are no matches, returns null.

SearchMany()

Works just like Search(), but returns an array of all objects matching the search. If there are no matches, returns an empty array.