0

I have a code block like this ;

$a='';

$Query =$db->prepare("UPDATE TblUsers
SET Age = :age
WHERE
 IsActive=1 ")
$Query->bindParam(":age",$a,PDO::PARAM_INT);
$Query->execute();

When i run this code i get this error ;

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'Age' at row 1'

But it will be nullable variable when i add '' . but i get this error. Where is my fail ?

Zibian Domichi
  • 185
  • 1
  • 11

1 Answers1

1

You need to use bindValue like below:-

$Query =$db->prepare("UPDATE TblUsers
SET Age = :age
WHERE
 IsActive=1 ")
$Query->bindValue(':age', $a, PDO::PARAM_INT);
$Query->execute();

bindParam takes a variable, to reference, and doesn't pull in a value at the time of calling bindParam.

Referecne:-How do I insert NULL values using PDO?

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98