如何在codeigniter中检查返回的查询是否正在运行
public function checkBranch($myData){
$qResult= array();
extract($myData);
$this->db->select('*');
$this->db->where('branch_name',$branch_name);
$this->db->where('branch_city',$branch_city);
//Here i want to execute else if query failed
if($query = $this->db->get('branch')){
$rowCount = $query->num_rows();
if ($rowCount<=0) {
//now check for is_main_branch status
$this->db->select('*');
$this->db->where_not_in('branch_name',$branch_name);
$this->db->where('branch_city',$branch_city);
$this->db->where('is_main_branch',"true");
$query = $this->db->get('branch');
$rowCount = $query->num_rows();
if($rowCount>0){
$qResult = array(
'q_status' => 'true' ,
'q_message' => "their is already a branch is set main for this city"
);
}
}else if($rowCount==1){
$qResult = array(
'q_status' => 'true' ,
'q_message' => "branch with city already exist in records"
);
}
}else{
$qResult = array(
'q_status' => 'true' ,
'q_message' => "inside else part"
);
}
return $qResult;
}
每当我调用此方法时,都会为给定参数返回结果,但是当表中当时给定参数不可用时,它将在控制台中抛出此消息
<p>Severity: Notice</p>
<p>Message: Undefined index: q_status</p>
所以我想在查询失败时执行else块,那么他们是否有任何一种方法可以检查查询是否执行,所以else块将执行