I usually use this code to read/get the result of an prepared MySQL SELECT:
$sqlname = $conn->prepare("SELECT name FROM test1 WHERE test2 = ?");
$sqlname->bind_param('s',$test);
$sqlname->execute();
$result = $sqlname->get_result();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$testname = $row['name'];
}
}
But when I know that there will only be one row in the result: Do I have to use a while loop with fetch_assoc
anyway or is there a better way?