PDO:在多个类中映射多个表(使用连接选择)

时间:2016-09-11 21:25:49

标签: php mysql database pdo

使用带有单个表的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")课程?

0 个答案:

没有答案