Use the $wpdb->get_results()
method to fetch data from the database.
global $wpdb;
$query = "SELECT * FROM {$wpdb->prefix}posts WHERE post_status = 'publish'";
$results = $wpdb->get_results($query);
foreach ($results as $post) {
echo $post->post_title . "<br>";
}