title: Custom where clauses in PHP prepared statement
body: <p>I'm reading about PDO and prepared statement, focused in Postgres.</p>
  
  <p>As I understood how ps is implemented in PHP, I can register a named query, then define variables for it and run it multiple times. But what happens when the use of where clauses depend on parameters.</p>
  
  <p>For exemple, if <code>!empty($param3)</code> then I add a where clause, but if it is empty that clause won't be used in the query.</p>
  
  <p>The best situation for this is a filter form to narrow a list of records: if no filter is used the query won't even use WHERE, while all filters may be used resulting in a big WHERE query.</p>
  
  <p>As I see now, I'd need to register 1 prepared statement for each situation, but that would result in lots of statements to maintain and test separately.</p>