title: How to make dynamic postgres prepared statements in PHP
body: <p>I'm trying to make some prepared statements in PHP using postgres.</p>
  
  <p>It's a bit difficult to explaing so i'll just show you:</p>
  
  <pre><code>$stmt = "SELECT * FROM customer WHERE zip = '$1'";
  
  if(isset($_POST["CITY"])){ 
     $stmt .= "AND city = '$2'";
  }
  
  if(isset($_POST["COUNTRY"])){ 
     $stmt .= "AND country = '$3'";
  }
  
  $result = pg_prepare("myconnection", "my query", $stmt);
  
  $result1 = pg_execute("myconnection","my query", array("0000","someCity","someCountry"));
  </code></pre>
  
  <p>Sorry if some of the code is wrong but it's a freehand example. What I need is to be able to make the prepared statement dynamic depending on if some variables isset/not-null.
  It doesn't seem to work when posting 3 variables in the array when the statement only expects 1 or if i only need to add $1 and $3 but not $2. I hope you understand.</p>
  
  <p>I need to use it this weekend, so I hope someone knows!</p>
  
  <p>Thank you in advance!</p>