title: PHP MySQL PDO and using OR
body: <p>I have a MySQL database and a query. It does not work as expected. If I write two queries, they will work just fine. I would like to modify my code and avoid using several queries.</p>
  
  <pre><code>$sql = $this-&gt;yhteys-&gt;prepare("SELECT ki_ka_ot.a_p1id
  FROM ki_ka_ot, ki_il, ka_il, ka, ka_ki, ka_ki_ot, ki_ka
  WHERE
  (
  ka_ki_ot.match = ? AND
  ki_ka_ot.a_points = 5 AND
  ki_ka_ot.a_points &gt; ki_ka_ot.b_points AND
  ki_ka_ot.endtime &gt; '0000-00-00 00:00:00'
  )
  OR
  (
  ka_ki_ot.match = ? AND
  ki_ka_ot.a_points &lt; 5 AND
  ki_ka_ot.a_points &lt; ki_ka_ot.b_points AND
  ki_ka_ot.endtime &gt; '0000-00-00 00:00:00'
  )
  AND ki_ka_ot.a_tid = ki_il.id
  AND ki_ka_ot.a_p1id = ka_il.id
  AND ki_ka.id = ki_ka_ot.chart_id
  AND ki_ka.charttype_id = ka_ki_ot.charttype_id
  AND ka_ki_ot.charttype_id = ka.id 
  AND ka_ki_ot.round_id = ka_ki.id
  AND ka_ki_ot.id = ki_ka_ot.place_id
  LIMIT 1");
  
  $sql-&gt;bindValue(1, 20, PDO::PARAM_INT);
  $sql-&gt;bindValue(2, 19, PDO::PARAM_INT);
  $sql-&gt;execute();
  
  $res = $sql-&gt;fetch(PDO::FETCH_ASSOC);
  </code></pre>