midgard_query_builder
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 midgard_query_builder(string 'MgdSchema class');__
The midgard_query_builder class used to be called MidgardQueryBuilder in the Midgard 1.7 series
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 midgard_query_builder('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";
}
?>
