Zend 2检查选择查询是否返回NULL

时间:2019-01-10 12:44:34

标签: php mysql zend-framework2 tablegateway

我正在使用Zend 2进行选择查询,如下所示。

我需要检查以上结果是否返回NULL(即,如果Email列为NULL)。

$checkEmailId = "Select EmailId from UsersNew where HashedUid='".$newUserId."'";
$Emailquery = $this->getUsersNewTable()->checkEmailnull($checkEmailId);

if(Email is Null)
{
   //EMail null
}
else{
   //EMail not null
}

模型文件:

public function checkEmailnull($sql){
        $data = $this->tableGateway->getAdapter()->driver->getConnection()->execute($sql);
        return $data;
}

1 个答案:

答案 0 :(得分:1)

$Emailquery”是ResultInterface

 $checkEmailId = "Select EmailId from UsersNew where HashedUid='".$newUserId."'";
 $Emailquery = $this->getUsersNewTable()->checkEmailnull($checkEmailId);

//now to get the current record 
$record = $Emailquery->current();

if(is_null($record["EmailId"]))
{
   //EMail null
}
else{
   //EMail not null
}