Created
January 9, 2013 12:43
-
-
Save anonymous/4492870 to your computer and use it in GitHub Desktop.
SqlBuilder example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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