Removing unwanted role after purchase

Just use $user->set_role( 'learner_member' ); instead of both lines where you are removing and adding the role.

Link to the docs.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)