Why Query is returning empty array?

you may need to wrap $slug in quotes

$course = $wpdb->get_results( "SELECT * FROM wp_posts where post_name="$slug"" );

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