0

I want to check if there is data in the database, I name the function CheckSOP, which will check if the there is data in the database, if the data do not exist yet then register the data otherwise it will skill. (Note this is custom Framework, just follow the rules like Laravel but does not like laravel.)

So how I am suppose to check it, I did try to use empty, null but fail, If I make !empty the data will be register, even there is no data or got data in it.

$checkSOP = sopActivity::CheckSOP($user_id, $unique_id['unique_id'], $season_id, $farm_id, $startDate);

if(empty($checkSOP)){   
$register_sop = sopActivity::RegisterSOP($user_id, $unique_id['unique_id'], $season_id, $farm_id, $startDate);
$acts_generate = sopActivity::GenerateSOP($user_id, $unique_id['unique_id'], $season_id, $farm_id, $startDate);
}

Below is my code for checkSOP

public static function CheckSOP($user_id, $unique_id, $season_id, $farm_id, $startDate){
               
      $db = DB::getInstance();
      $query = "SELECT COUNT(*) FROM sop_records
                WHERE  start_date = '$startDate' AND rec_sop_unique_id = '$unique_id' 
                AND season_id = '$season_id'";
            
            $getSOP = $db->prepare($query);
            $getSOP -> execute();
            
            return $getSOP;        
        }

0 Answers0