breaks at my while loop. have been reading the php manual but can’t figure out what im doing wrong here…
$pdo is call to my db connection
function getSelectedPhoto($the_selected_id) {
global $pdo;
$id = $the_selected_id;
$stmt = $pdo->prepare("SELECT handle, src FROM images WHERE id = :id LIMIT 1");
$vars = array(':id' => $id);
$result = $stmt->execute($vars);
if($result) {
while($row = $result->fetchObject()) {
echo '<img src="../' . $row->src . '" alt="image" /><br />';
echo '<p id="handle">' . $row->handle . '</p>';
}
} else die("There was some problem");
}
According to the manual “PDOStatement::execute” the
execute()-method returnstrueorfalseand not the result:Of course this will lead to “Call to a member function fetchObject() on a non-object” when calling
$result->fetchObject().Your code should be like this: