title: Insert NULL instead of empty string with PDO
body: <p>I have a table which has some nullable fields and when the user enters nothing into the HTML form field, I want to insert NULL into that field, not an empty string (this is important as some of my SELECTs on these tables later use conditions such as WHERE x IS NOT NULL).</p>
  
  <p>However, this version of bindParam code inserts an empty string into the nullable field instead of NULL.</p>
  
  <pre><code>$stmt2-&gt;bindParam(':title', $title, PDO::PARAM_STR);
  </code></pre>
  
  <p>I've been reading quite a bit and figured out that this is the answer to insert null into the field instead:</p>
  
  <pre><code>$stmt2-&gt;bindParam(':title', $title, PDO::PARAM_NULL);
  </code></pre>
  
  <p>But this means I need to pre-check all parameters that are being passed to nullable fields to determine if they are empty, and if so pass the <code>PDO::PARAM_NULL</code> instead of <code>PDO::PARAM_STR</code>. I can of course do this, but was hoping there might be a setting which would just tell PDO if it encounters an empty string, insert null instead.</p>
  
  <p>I stumbled across this</p>
  
  <pre><code>$this-&gt;dbh-&gt;setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING);
  </code></pre>
  
  <p>But it has no effect and with further research I'm thinking this only affects record on the way out, not on the way in.</p>
  
  <p>Any options other than pre-checking the variables?</p>