Can I create a taxonomy term that mirrors the name of a new custom post?

I recently ran into a similar situation. While I can’t currently remember the source, the code below will create a new entry into your taxonomy of choice, it could serve as the base for your needs.

//Automatically creates a category in the case log and adds it to the post.

function add_title_as_category( $postid ) {
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
   $post = get_post($postid);
if ( $post->post_type == 'case') { // change 'post' to any cpt you want to target
    $term = get_term_by('slug', $post->post_name, 'case-log');
if ( empty($term) ) {
  $add = wp_insert_term( $post->post_title, 'case-log', array('slug'=> $post->post_name) );
  if ( is_array($add) && isset($add['term_id']) ) {
    wp_set_object_terms($postid, $add['term_id'], 'case-log', true );
  }
}

}
}
add_action(‘save_post’, ‘add_title_as_category’);

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