MidgardQueryBuilder
Midgard Query Builder is a special Midgard PHP class which enables developers to optimize SQL queries used in a Midgard application. Query Builder (QB) may be used only with MgdSchema registered types.
Creating new Query Builder object instance
Query Builder is instantiated by giving it the name of the MgdSchema type being queried.
object MidgardQueryBuilder(string 'MgdSchema class');
MidgardQueryBuilder class name is deprecated since Midgard 1.8. Use midgard_query_builder class name. Deprecated name will be removed in Midgard 2.0.
Midgard Query Builder methods
- add_constraint
- add_placeholder_constraint
- add_order
- begin_group
- end_group
- execute
- set_limit
- set_offset
- set_lang
- count
Usage example:
<?php
// Instantiate Query Builder for an Article object
$qb = new MidgardQueryBuilder('midgard_article');
// List articles only in topic 123
$qb->add_constraint('topic', '=', 123);
// Run the query
$articles = $qb->execute();
// Show the articles
foreach ($articles as $article)
{
echo "<h2>{$articles->title}</h2>\n";
}
?>
