给定以下所需的SQL,必须满足Cond1 和 Cond2 或必须满足Cond3的选择,才可以使用正确的方法getQuery()
来实现?
所需的SQL: 括号中的Condition1和Condition2)
SELECT * FROM #__myTable
WHERE (condition1=true AND condition2=true) OR condition3=true
使用链接: 在-> where()中指定OR
$query = $db->getQuery(true);
$query->select('* FROM #__myTable')
->where('condition1 = true AND condition2 = true','OR')
->where('condition3 = true');
结果SQL:(SQL缺少括号)
SELECT * FROM scm_myTable
WHERE condition1 = true AND condition2 = true OR condition3 = true
使用 在-> where()中指定OR的数组
$query = $db->getQuery(true);
$conditions12 = array(
'condition1 = true',
'condition2 = true'
);
$conditions3 = array(
'condition3 = true'
);
$query->select('* FROM #__myTable')
->where($conditions12, 'OR')
->where($conditions3);
结果SQL:(SQL缺少括号)
SELECT * FROM scm_myTable
WHERE condition1 = true OR condition2 = true OR condition3 = true