php – Server 500 error when running shortcode function to list table() objects

I am constantly getting the below script returning Server 500 errors. Whilst I have followed the WP Codex almost to the letter I can’t seem to get this to work.

  1. The PHP is saved in the functions.php of the theme
  2. The wp_countries table is saved in the WPDB (not a separate DB)

Any guidance would be greatly appreciated.

function country_shortcode(){
        global $wpdb;
        $countries = $wpdb->get_results(
        "SELECT * FROM wp_countries", OBJECT);
        foreach ($countries as $country) {
        echo $country->country_name;
}
add_shortcode('countries','country_shortcode');