2015-04-22 87 views
0

空值,這是我的查詢:的Yii不返回是從數據庫

SELECT * FROM mytable WHERE `USER` = '1599' AND `id` = '124253' AND `wednesday` IS NULL 

這是PHP代碼:

$check = Test::model()->find("id =:id and user =:user and ".$day." =:day ", array(":id" => $check_lunch_per_day, ":user" => $user, 'day'=> null)); 

闖闖:

$check = Test::model()->find("id =:id and user =:user and ".$day." =:day ", array(":id" => $check_lunch_per_day, ":user" => $user, 'day'=> 'IS NULL')); 

但結果該檢查始終爲空。我該怎麼辦?如果它爲空,我想獲得星期三列值。

+1

你所謂的 「週三」 一欄?或稱爲「日」 – Kibi

+1

你有一個在參數陣列'天'缺少冒號應該是':日' –

回答

0

這應該工作,

設置:dayIS NULL

$check = Test::model()->find("id =:id and user =:user and ".$day." =:day ", 
array(":id" => $check_lunch_per_day, ":user" => $user, ':day'=> 'IS NULL'));