Problème execute();

Par Konix, il y a 6 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.

Ce que je fais

Je cherche a récuperer des infos de ma bdd

<?php try { $bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', ''); echo 'Connection réussit'; } catch (Exception $e) { die('Erreur : ' . $e->getMessage()); } var_dump($bdd); $bddInfos = $bdd->prepare("SELECT * FROM infos"); $bddExes = $bddInfos->execute(); $bddSees = $bddInfos->fetch(PDO::FETCH_ASSOC); var_dump($bddInfos); var_dump($bddExes); var_dump($bddSees); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <h1>Liste</h1> <ul> <?php foreach ($bddSees as $bddSee): ?> <li> <?= $bddSee['name'] ?> <?= $bddSee['age'] ?> </li> <?php endforeach; ?> </ul> </body> </html>

Ce que je veux

je suis censé obtenir les noms des personnes dans ma bdd, ainsi que leur age

Ce que j'obtiens

Connection réussit C:\wamp64\www\TutoPHP\w\index.php:13: object(PDO)[1] C:\wamp64\www\TutoPHP\w\index.php:21: object(PDOStatement)[2] public 'queryString' => string 'SELECT * FROM infos' (length=19) C:\wamp64\www\TutoPHP\w\index.php:22:boolean false C:\wamp64\www\TutoPHP\w\index.php:23:boolean false Liste ( ! ) Warning: Invalid argument supplied for foreach() in C:\wamp64\www\TutoPHP\w\index.php on line 39 Call Stack # Time Memory Function Location 1 0.0008 363256 {main}( ) ...\index.php:0

1 réponse

Konix, il y a 6 ans

J'ai réussit a résoudre le problème :)
Si vous tomber sur le meme problème et que vous etes sur wamp, avec une base de données MySQL, faut renseigné le port comme ceci 'mysql:host=localhost;port=3308;dbname...