Using Yii CDbCriteria to query a table in a plugin First question I guess is "should I be using CDbCriteria at all, or am I overcomplicating things"? 

Secondly if I'm ok using it, how do I achieve the following SQL query:

SELECT * FROM myTable 
WHERE cottage=3 
AND (fromDate BETWEEN '2015-01-01' AND '2015-01-11' 
OR toDate BETWEEN '2015-01-01' AND '2015-01-11');


So far I've got this:

$criteria = new \CDbCriteria();
$criteria-&gt;addCondition('cottage=' . $booking-&gt;cottage);
$criteria-&gt;addBetweenCondition('fromDate', $booking-&gt;fromDate, $booking-&gt;toDate);
$criteria-&gt;addBetweenCondition('toDate', $booking-&gt;fromDate, $booking-&gt;toDate, 'OR');
$previousBookings = BookingEngine_BookingsRecord::model()-&gt;findAll($criteria);


Which nearly gets me there, the only issue is when I dump the $criteria-&gt;condition, the brackets are in the wrong place. So I get this:

((cottage=3) AND (fromDate BETWEEN :ycp2 AND :ycp3)) OR (toDate BETWEEN :ycp4 AND :ycp5)


The cottage and fromDate are bracketed together, whereas I want the fromDate and toDate bracketed together instead.

Other than manually writing the SQL, is there a more straightforward way of doing this, I feel I'm really overdoing a seemingly easy query!

UPDATE: I did rearrange the addCondition and addBetweenCondition calls as such:

$criteria = new \CDbCriteria();
$criteria-&gt;addBetweenCondition('fromDate', $booking-&gt;fromDate, $booking-&gt;toDate);
$criteria-&gt;addBetweenCondition('toDate', $booking-&gt;fromDate, $booking-&gt;toDate, 'OR');
$criteria-&gt;addCondition('cottage=' . $booking-&gt;cottage);
$previousBookings = BookingEngine_BookingsRecord::model()-&gt;findAll($criteria);


and that did in fact solve the problem. However it does feel like it's working by accident rather than by design. I think Jørgen's answer below  is a bit more straightforward, so I went with that instead.
Try this (untested)

$criteria = 'cottage = :cottage and ((fromdate between :d1 and :d2) or(toDate between :d1 and :d2))';
$params = array('cottage' =&gt; $booking-&gt;cottage, 'd1' =&gt; $booking-&gt;fromDate, 'd2' =&gt; $booking-&gt;toDate);
$previousBookings = BookingEngine_BookingsRecord::model()-&gt;findAll($criteria, $params);