Display Only One Category

Here’s snippet to display first category from post.

$category = get_the_category();

if ( $category[0] ) {
    echo '<h2><a href="' . get_category_link( $category[0]->term_id ) . '">' . $category[0]->cat_name . '</a></h2>';
}

Original idea of the code is from WordPress Codex

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