Can't update row in database

I’m new here an i have a problem with udating my database.
I’ve tried it with ActiveRecord and I even tried it by creating an Sql command.
please tell me where I’m wrong :disappointed_relieved:


             $test=Yii::$app->db->createCommand('UPDATE `timetable` SET `status`= :status, `bookingID` = :bookingID WHERE `field`= :field AND `id`= :id')
        ->bindValue(':bookingID', $this->_id)
        ->bindValue(':field', $field)
        ->bindValue(':id', $id)
        ->bindValue(':status', 'status');

Active Record:

        $model = Timetable::find()->where(['id'=> $id, 'field'=>$field])->one();
        $model->status = $status;
        $model->bookingID = $id;
        echo 'update successfull';
        }else{echo'update failed';}

you should probably use $test->execute() instead of query.

if this shows 'update failed' you probably have validation errors, use ->save(false) to skip validation, or print_r($model->getErrors()); to show validation errors.


You might need to ensure the field has a rule in it. Otherwise you can always use $model->save(false) to ignore validation.