【发布时间】:2016-10-21 14:35:49
【问题描述】:
出于纯粹的好奇,谁能快速告诉我这是否可能?我没有那样实现它,但回头看,我想知道它是否可以做到。这是场景:
产品、服务表和定义成本之间的关系表
Product ID | Name 1 | Product A 2 | Product B Service ID | Name 1 | Service A 2 | Service B 3 | Service C Price ID | Cost | Product ID | Service ID 1 | 1 | 1 | 1 2 | 2 | 1 | 3 3 | 3 | 2 | 2 4 | 4 | 2 | 3
所以如果有表数据对象,就会有:
- 具有以下属性的类产品:id、名称、服务数组。
- Class Service 具有属性:id、name、cost
//$query = obtain a list of all products with services and prices;
//$query = obtain a product and all it's associated services and prices;
$statement = $pdo->prepare($query);
$statement -> execute();
$results = $statement ->fetchAll(PDO::FETCH_CLASS,"Product");
【问题讨论】: