1

I'm using the following code in an attempt to bind NULL to an integer column on a MySQL table:

$query->bindValue(1, null, \PDO::PARAM_INT);

However, this causes the value in the column to be "0" instead of NULL.

How can I force the column to be NULL instead of 0?

TaylorOtwell
  • 7,177
  • 7
  • 32
  • 42
  • possible duplicate of [How do I insert NULL values using PDO?](http://stackoverflow.com/questions/1391777/how-do-i-insert-null-values-using-pdo) – Marc B Jul 14 '11 at 14:56
  • @Marc - as you can see, I'm using the accepted solution. That solution works for a string column. Not for an integer, which is specifically what I'm asking about. – TaylorOtwell Jul 14 '11 at 14:56
  • you're telling PDO you're passing an INT, so null gets typecast to 0. Try PDO_::PARAM_NULL – Marc B Jul 14 '11 at 14:59

1 Answers1

3
bindValue(':param', null, PDO::PARAM_NULL);
Raffael
  • 19,547
  • 15
  • 82
  • 160