title: Why is PDO treating a blank value as null?
body: <p>I'm trying to insert a record in an automobile table.  Here's a trimmed down version of the table.  </p>
  
  <p><strong>NOTE</strong>: this is not a real life working model, should not be used or evaluated as such. I'm just showing the problem I'm having in a simplified way.  </p>
  
  <pre><code>mysql&gt; describe desc_autos;
  +-----------------+------------------+------+-----+---------------------+----------------+
  | Field           | Type             | Null | Key | Default             | Extra          |
  +-----------------+------------------+------+-----+---------------------+----------------+
  | car_id          | int(10) unsigned | NO   | PRI | NULL                | auto_increment |
  | automobile_name | varchar(25)      | NO   | MUL |                     |                |
  +-----------------+------------------+------+-----+---------------------+----------------+
  7 rows in set (0.00 sec)
  
  mysql&gt; select count(*) FROM desc_autos WHERE automobile_name IS NULL;
  +----------+
  | count(*) |
  +----------+
  |        0 |
  +----------+
  1 row in set (0.00 sec)
  
  mysql&gt; select count(*) FROM desc_autos WHERE automobile_name = '';
  +----------+
  | count(*) |
  +----------+
  |    19322 |
  +----------+
  1 row in set (0.02 sec)
  
  +-------------+
  CREATE TABLE `desc_autos` (
    `car_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `automobile_name` varchar(15) NOT NULL,
    PRIMARY KEY (`car_id`)
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
  +-------------+
  1 row in set (0.00 sec)
  </code></pre>
  
  <p>So you see the <code>automobile_name</code> field is <code>NOT NULL</code>, and blank values are being shown for many records.  <em>(Disregard field names - just accept there is a field with non-null values)</em></p>
  
  <p>I am converting from native MySQL functions to PDO.  If I insert a record with a non-blank <code>automobile_name</code> value, no problem - works fine.   If <code>automobile_name</code> is blank, PDO balks. </p>
  
  <pre><code>    $automobile_name = '';
      try 
      {
          $q = "
              INSERT INTO
                  desc_autos
                  (
                      automobile_name
                  )
              VALUES
                  (
                      :automobile_name
                  )
          ";
          $stmt = $dbx_pdo-&gt;prepare($q);
          $stmt-&gt;bindParam(':automobile_name',    $automobile_name,   PDO::PARAM_STR);
          $stmt-&gt;execute();
          return true;
      } catch(PDOException $err) {
          log_error();
          return false;
      }       
  }
  </code></pre>
  
  <p>This results in the following error: </p>
  
  <pre><code>Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'automobile_name' cannot be null
  </code></pre>
  
  <p>I thought I had to implicitly tell PDO to insert a NULL value, otherwise blank values would be inserted as... blank values.  </p>
  
  <p>Ex: </p>
  
  <blockquote>
    <p>$stmt->bindValue(':automobile_name', !empty($automobile_name) ?
    $automobile_name   : NULL, PDO::PARAM_STR);</p>
  </blockquote>
  
  <p>I'm not needing to insert NULLs in this case - I need to drop a blank, non-null value in the given field.  </p>
  
  <p><strong>The question:</strong></p>
  
  <p>Why is PDO treating a blank value as null?  </p>