I have this code below. What i want is to avoid the use of **global $db** since i've heard it's bad practice, and i'm looking for more robust/well implemented functionality.

connection.php

```
<?php
try {
    $db = new PDO('mysql:host=127.0.0.1;dbname=blop', 'blop', 'root');
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (Exception $e) {
    $error = $e->getMessage();
    echo $error;
}
?>

```

Admin.php

```
<?php
class Admin {

    public function fetch_data() {
        global $db;

        $sql = "SELECT * FROM `people` ORDER BY `id` DESC";
        $result = $db->query($sql);

        return $result;
    }

    public function fetch_row_count() {
        global $db;

        $sql = "SELECT * FROM `people`";
        $result = $db->query($sql);
        $num_rows = $result->rowCount();

        return $num_rows;
    }

    public function deleteAll() {
        global $db;

        $deleteAll = $db->prepare("DELETE FROM `people`");
        $deleteAll->execute();
    }

    public function deleteData($id) {
        global $db;

        $id = $_POST['id'];
        $deleteData = $db->prepare("DELETE FROM `people` WHERE `id` = '$id'");
        $deleteData->execute();
    }
}
?>

```