The following code will help you to fetch data from the database in Drupal 8/9.
$table =’my_table’;
$db = \Drupal::database();
$query = $db->query(“SELECT id, name FROM {$table}”);
$result = $query->fetchAll();
ref : https://www.drupal.org/docs/drupal-apis/database-api/static-queries.