Function to delete a term when a custom post with the same slug is trashed

do you know where is your code fails? Is the hook runs properly? One thing for sure, term_exists() returns the ID not an object. Also $wpdb is not needed at all.

wp_delete_term($theterm, 'byartist');

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