0

The following code produces the mentioned error. What is the fix for PHP 8.2?

PHP Warning – yii\base\ErrorException Trying to access array offset on value of type bool

In /var/www/html/atmtest/frontend/modules/atm/controllers/TwmgdtreportController.php 
at line 132

        $date = $model->tr_date;
 
        //$drID = Dailyroutine::find()->select('dr_id')->where(['dr_date' => $date, 
        //'dr_empid' => $user])->column();
 
        $post = Yii::$app->db->createCommand('SELECT * FROM dailyroutine WHERE 
        dr_date=:dr_date AND dr_empid=:dr_empid')
           ->bindValue(':dr_date', $date)
           ->bindValue(':dr_empid', $user)
           ->queryOne();
 
           $drID = $post['dr_id'];

        //print(json_encode($dr));
        //die(); 
KrisPbcon
  • 21
  • 2
  • Method `queryOne()` can return `false` when the query returns empty result. Obviously, you can't access `['dr_id']` on `false`. – Michal Hynčica Jan 19 '23 at 15:25

1 Answers1

0

I found the fix

if(is_array($post)){
   $drID = $post['dr_id'];
}
KrisPbcon
  • 21
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 27 '23 at 03:40