Home >Backend Development >PHP Tutorial >A sql statement method about zentaophp framework
<code>php</code><code>return $this->dao->select('id,amount,dept,signedBy,begin,end,bourse,openBank')->from(TABLE_CONTRACT) ->where('deleted')->eq(0) ->beginIF($mode=='bysearch')->andWhere('begin','between',$startDate,$endDate) ->orWhere('end')->between($startDate,$endDate) ->fi() ->beginIF($dept) ->andWhere('dept')->eq($dept) ->fi() // ->groupBy($groupBy) ->orderBy($orderBy) ->fetchAll(); </code>
This code can generate such sql
<code>sql</code><code>SELECT id,amount,dept,signedBy,begin,end,bourse,openBank FROM `crm_contract` wHeRe deleted = '0' AND dept = '820011' AND begin BETWEEN '2015-03-01' AND '2015-03-31' OR end BETWEEN '2015-03-01' AND '2015-03-31' oRdEr bY `signedBy` desc,`amount` desc </code>
How to write the above ORM statement to form the following SQL statement
<code>sql</code><code>id,amount,dept,signedBy,begin,end,bourse,openBank FROM `crm_contract` wHeRe deleted = '0' AND dept = '820011' AND (begin BETWEEN '2015-03-01' AND '2015-03-31' OR end BETWEEN '2015-03-01' AND '2015-03-31' ) oRdEr bY `signedBy` desc,`amount` desc </code>
A simple explanation is how to add parentheses outside the two where conditions of begin and end?
<code>php</code><code>return $this->dao->select('id,amount,dept,signedBy,begin,end,bourse,openBank')->from(TABLE_CONTRACT) ->where('deleted')->eq(0) ->beginIF($mode=='bysearch')->andWhere('begin','between',$startDate,$endDate) ->orWhere('end')->between($startDate,$endDate) ->fi() ->beginIF($dept) ->andWhere('dept')->eq($dept) ->fi() // ->groupBy($groupBy) ->orderBy($orderBy) ->fetchAll(); </code>
This code can generate such sql
<code>sql</code><code>SELECT id,amount,dept,signedBy,begin,end,bourse,openBank FROM `crm_contract` wHeRe deleted = '0' AND dept = '820011' AND begin BETWEEN '2015-03-01' AND '2015-03-31' OR end BETWEEN '2015-03-01' AND '2015-03-31' oRdEr bY `signedBy` desc,`amount` desc </code>
How to write the above ORM statement to form the following SQL statement
<code>sql</code><code>id,amount,dept,signedBy,begin,end,bourse,openBank FROM `crm_contract` wHeRe deleted = '0' AND dept = '820011' AND (begin BETWEEN '2015-03-01' AND '2015-03-31' OR end BETWEEN '2015-03-01' AND '2015-03-31' ) oRdEr bY `signedBy` desc,`amount` desc </code>
A simple explanation is how to add parentheses outside the two where conditions of begin and end?