What are the advantages and disadvantages of using separate tables for each class in a PHP application?

Using separate tables for each class in a PHP application can help organize data more efficiently and make it easier to manage relationships between different classes. However, it can also lead to a more complex database structure and potentially slower performance when querying data across multiple tables.

// Example of using separate tables for each class in a PHP application

class User {
    private $db;

    public function __construct($db) {
        $this->db = $db;
    }

    public function getUserById($id) {
        $query = "SELECT * FROM users WHERE id = :id";
        $stmt = $this->db->prepare($query);
        $stmt->bindParam(':id', $id);
        $stmt->execute();
        return $stmt->fetch();
    }
}

class Product {
    private $db;

    public function __construct($db) {
        $this->db = $db;
    }

    public function getProductById($id) {
        $query = "SELECT * FROM products WHERE id = :id";
        $stmt = $this->db->prepare($query);
        $stmt->bindParam(':id', $id);
        $stmt->execute();
        return $stmt->fetch();
    }
}

$db = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');
$user = new User($db);
$product = new Product($db);

$userData = $user->getUserById(1);
$productData = $product->getProductById(1);

print_r($userData);
print_r($productData);