<?php
$stmt = $dbh->prepare("SELECT * FROM USER where name = ?");
if ($stmt->execute(array($_GET['name']))) {
while (??????) {
print_r($row);
}
}
?>
What will you write at line number 4 to fetch data from database?
$row = $stmt->fetch()
Correct:
$row = $stmt->fetch()
Explanation: Answer option C is correct.
The following example explains the working of the fetch method:
<?php
$stmt = $dbh->prepare("SELECT * FROM USER where name = ?");
if ($stmt->execute(array($_GET['name']))) {
while ($row = $stmt->fetch()) {
print_r($row);
}
}
?>
Answer options D, A, and B are incorrect. These are not valid formats for fetching data from prepared statements.