I want to use prepared statements to retrieve some result from the database and have tried the below. But It always returns []. Is this the correct way to return rows via a prepared statement?
$stmt = $con->prepare('SELECT bookingId,locationName
FROM bookings
WHERE username= ?');
$stmt->bind_param('s', $one);
$stmt->execute();
$stmt->bind_result($id, $loc);
$output = array();
while($row = $stmt->fetch()){
$output[] = $row;
}
$stmt->close();
print(json_encode($output));
bind_resultline, you don't use both$idand$locanyway, or use it within the loop ($output[$id] = $loc).