-1

Before, I insert data to database using normal sql code and I use ("") to insert the empty var into database.

Now I use pdo and I use (NULL) to insert the empty value to database.

I know that ("") and (NULL) is different. But I get problem to script the variable that´s NULL....well maybe I´m not good at explaining. let´s see my script:

$problem=$rs['problem']; ///Here comes with the NULL from database.

    if (is_null($problem)) {
        echo"this is null";
    } else {
        echo"this is not null";
    } 

OR
    if (empty($problem) ) {
        echo "this is null";
    } else {
        echo "this is not null";
    } 

OR 
    if (isset($problem)==NULL) {            
        echo "this is null";
    } else {
        echo "this is not null ";           
    }

Whether there´re empty or have data in the table, the result I get from these 3 script is only "this is null"

I have no idea how I can get this correct.

4

1 回答 1

0

您的意思是说空值可以是 NULL 或 ''(空字符串)?

尝试这个:

if (is_null ($problem) || empty ($problem))
{
   echo "This is null";
}
else
{
   echo "This is not null";
}

顺便说一句,我不确定这是否是拼写错误,但您在回声后缺少一个空格。它应该是echo "This is null";

于 2013-08-11T08:05:25.353 回答