title: MySQL Insert to NULL INT Column with PHP sprintf
body: <p>I'm trying to format a mysql insert statement using php <code>sprintf</code> but doing so inserts a <code>0</code> rather than <code>NULL</code> into the record column. I'm looking for a way around this while still using <code>sprintf</code> for formatting:</p>
  
  <pre><code>$query = sprintf("INSERT INTO `efix_lines`
                       (EventID, Serial, SerialRequired, PartNumber,
                        MfgRev, DefectID, CircuitReference, CreatorID,
                        CreatorName, Created)
                     VALUES (%d, '%s', %d, '%s', '%s', %d, '%s', %d, '%s', '%s')",
                        $oSubmitData['EventID'],
                        EVL($oSubmitData['Serial'], NULL),
                        EVL($oSubmitData['SerialRequired'], NULL),
                        EVL($oSubmitData['PartNumber'], NULL),
                        EVL($oSubmitData['MfgRev'], NULL),
                        EVL($oSubmitData['DefectID'], NULL),
                        EVL($oSubmitData['CircuitReference'], NULL),
                        $oSubmitData['CreatorID'],
                        $oSubmitData['CreatorName'],
                        $pDate );
  
  //I made this quick EVL function to help with shorthand ternary operators within my actual syntax
  function EVL( $var1, $var2 ){
     return ( empty( $var1 ) ? $var2 : $var1 );
  };
  </code></pre>
  
  <p>The problem is occurring on <code>DefectID</code> column when attempting to insert <code>NULL</code> since it is empty.  <code>sprintf</code> wants to insert an integer as <code>%d</code> dictates, so it inserts <code>0</code> rather than <code>NULL</code>.  What can I do?</p>