私は実際にPHPでクラスと次のようなDAOクラスをコードしています。 dbDAOの内容はデータベースのPDO接続のみです。データベースに含まれるすべての製品をインデックスページに表示したい。データベースからすべての製品を表示する最善の方法は、DAOクラスにあるのか、オブジェクト製品を使用するのですか? DAOクラスは自分のデータベース内のコンテンツのみを変更するためのクラスですか?クラスとDAOを使用したデータベースのデータを表示
ここに私のコードです:
DAOクラス:
class ProduitDao extends dbDAO
{
public function displayProduits()
{
$product = $this->bdd->prepare("SELECT * FROM products");
$product->execute();
while ($displayProduct = $product->fetch())
{
?>
<div class="prodname">
<?php
echo '<a href="./product.php?id='.$displayProduct['no'].'"</a>';
echo '<img src="images/produits/'.$displayProduct['image'].'" alt=" '.$affichageProduit['nom'].' "</img>';
?>
</div>
<?php
}
}
Productクラス:
public function __construct($no, $img)
{
$this->no = $numero;
$this->img = $img;
}
// GET and SET goes here
Tancks!
私は今参照してください!タンクスの助けを借りて! :) – SurveyVisual