wp_set_object_terms not working inside loop

You can pass an array of terms to wp_set_object_terms, there is no need for the for each:

$genres= array('action', 'comedy', 'horror');
$ret = wp_set_object_terms( $postId, $genres, 'genres');

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