Reputation: 460
I would like to user prepared request with PDO but it doesn't seem to return any result while the query request do return some.
Here, there are my two requests :
Prepared request :
$req = $this->bdd->prepare('SELECT u.id, u.username, hm.desc, s.name AS shop, hm.amount, hm.date FROM history_members AS hm LEFT JOIN users AS u ON u.id = hm.user_id LEFT JOIN shops AS s ON s.id = hm.shop_id WHERE hm.user_id = :id');
$req->bindValue(':id', $id, PDO::PARAM_INT);
$data = $req->fetchAll(PDO::FETCH_ASSOC);
$req->closeCursor();
Query request :
$req = $this->bdd->query('SELECT u.id, u.username, hm.desc, s.name AS shop, hm.amount, hm.date FROM history_members AS hm LEFT JOIN users AS u ON u.id = hm.user_id LEFT JOIN shops AS s ON s.id = hm.shop_id WHERE hm.user_id = '.$id);
$data = $req->fetchAll(PDO::FETCH_ASSOC);
$req->closeCursor();
What am I doing wrong with the prepared request ?
Upvotes: 0
Views: 85
Reputation: 9351
you did not execute your query. First execute query then fetch the result.
Upvotes: 1