PDO select retourne mes colonnes dupliquées
J'essaye de passer de mysqli à PDO et je bloque à afficher les résultats d'un select.
Dans ma BD j'ai la table produit avec les colonnes suivantes:
id_Produit, id_Categorie, nom, prix, prixDetaillant, description, qtSTock, qtMin
Ma classe pour PDO
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <?php
final class BDService
{
private $BD_Interne;
public function __construct()
{
try
{
$this->BD_Interne = new PDO('mysql:host=localhost;dbname=bd','root','');
$this->BD_Interne->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e)
{
echo "Échec : ".$e->getMessage();
}
}
public function Select($sql)
{
$select = $this->BD_Interne->prepare('SELECT * from produit');
$select->execute();
return $select->fetchAll();
}
}
?> |
Code pour affichier :
Code:
1 2 3 4 5 6 7 8 9 10
| $resultat = $bd->Select("");
foreach($resultat as $ligne)
{
foreach($ligne as $elem)
{
echo $elem." ";
}
echo "<br>";
} |
le résultat donne :
id_Produit, id_Produit, id_Categorie, id_Categorie, nom,nom...