There are currently 3 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
1101 2
【實驗】PHP對MySQL的NULL和空字符串的檢測
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 9/3/15 18:05
$sql = "SELECT NULL, ''";
$row = get_result_row($sql);
echo (int)is_null($row[0]); //1
echo (int)empty($row[0]); //1
echo (int)is_null($row[1]); //0
echo (int)empty($row[1]); //1
exit;

輸出1101
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 9/3/15 18:08
因此,檢測MySQL的字段值是否為NULL時,可直接使用is_null函數。
檢測是否為空字符串時,需要這樣判斷:
if (!is_null($row[1]) && empty($row[1])) {
  echo "是空字符串";
}
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 3 Posted at: 9/3/15 18:09
當值為NULL或空字符串時,empty都輸出1
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 1101 Replies: 2
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 9/3/15 18:09
Announcements