[英]PHP PDO when fetching data, can data be fetched into an Object which contains another Object?
出於純粹的好奇心,誰能迅速告訴我是否可行? 我沒有那樣實現,但是回想一下,我想知道是否可以實現。 這是場景:
產品,服務表以及兩者之間的關系表
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
因此,如果有表數據對象,則將有:
//$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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.