SQL 'select' query where parameter is NULL

Hi,

is it possible to run a SELECT query where the parameter is NULL?

I am trying the following but it does not work for me:


$connection=Yii::app()->db;

		

$sql = "SELECT id, categoryName FROM categories WHERE parentId=:parentId";

		

$command=$connection->createCommand($sql);


$parentId = NULL;		


$command->bindParam(":parentId",$parentId,PDO::PARAM_INT);

		

print_r($command->queryAll());

I also tried the following without any luck:


$command->bindParam(":parentId",$parentId,PDO::PARAM_NULL);

Your query won’t work even without parameter binding. It isn’t a valid MySQL query.

You need to use something like:

WHERE ‘column’ IS NULL

Please read:

http://stackoverflow.com/questions/6827010/null-values-in-where-clause

Short answer: Null = nothing, so you can’t test for column=nothing. Column can never EQUAL nothing.

Thanks a lot!

how to fetch database values in controller part using ajax variable based in my code is given error