How do I insert a post with custom post type and relate it to a custom taxonomy?

Try changing this line

  wp_set_object_terms( $post_id, array($cat_ids), 'categorycourses', false);

to

  wp_set_object_terms( $post_id, $cat_ids, 'categorycourses', false);

$cat_ids is already an array and you are writing with in array again.
Hope it helps.

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