Sushivam
Sushivam

Reputation: 3107

Zend 2 check if select query returned NULL

I am using select query using Zend 2 like below.

I need to check if the above result returned NULL (ie) if the Email column is NULL).

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

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

Model file:

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

Upvotes: 0

Views: 75

Answers (1)

Gautam Rai
Gautam Rai

Reputation: 2505

Here "$Emailquery" is 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
}

Upvotes: 1

Related Questions