使用带有单个表的SELECT语句
SELECT * FROM customer WHERE id = :id
我可以轻松地映射Customer类中的输出
class Customer
{
private $id;
private $name;
private Company;
// etc...
}
以这种方式
// ...
return $stmt->fetchALL(\PDO::FETCH_CLASS, "Customer");
但是在包含两个或更多表的查询中
SELECT * FROM customer AS cu JOIN company AS co ON cu.company_id = co.id WHERE cu.id = :id
class Company
{
private $id;
private $name;
// etc...
}
如何使用Customer
使用Company
数据填充$stmt->fetchALL(\PDO::FETCH_CLASS, "Customer")
课程?