Skip to content

Instantly share code, notes, and snippets.

Created January 9, 2013 12:43
Show Gist options
  • Save anonymous/4492870 to your computer and use it in GitHub Desktop.
Save anonymous/4492870 to your computer and use it in GitHub Desktop.
SqlBuilder example
$stmt = new SqlBuilder();
$stmt->select()
->setOptions('SQL_CALC_FOUND_ROWS')
->from(array('a' => 'my_table'))
->fields(array(
'a.id',
'a.parid',
'a.caption'
))
->joinInner(
array('cat_info' => 'my_table_2'),
'a.parid = cat_info.id',
array(
'cat_caption' => 'cat_info.caption',
'cat_alias' => 'cat_info.alias'
)
)
->where('a.fl_hide = ?', 0)
->order('a.pdate DESC')
->limit($limit)
;
if($some_var > 0){
$stmt->where('a.some_var = ?', $some_var);
}
if(is_array($versions) && count($versions)){
$stmt->where(new SqlBuilderExpression('a.osversion IN('.implode(',', $versions).')'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment