Here is my code:
<?php
$db_host        = 'localhost';
$db_user        = 'root';
$db_pass        = 'root';
$db_database    = 'drmahima_com';
$link = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a DB connection');
mysqli_query($link, "SET names UTF8");
function temp() {
    $patient = mysqli_fetch_assoc(mysqli_query($link, "SELECT name,dob FROM patients WHERE id='69'"));
    echo $patient['name'];
}
temp();
?>
When I run this, the query doesn't seem to execute and nothing shows up on the page. However, if I remove the function and just change the code to this:
<?php
$db_host        = 'localhost';
$db_user        = 'root';
$db_pass        = 'root';
$db_database    = 'drmahima_com';
$link = mysqli_connect($db_host,$db_user,$db_pass,$db_database) or die('Unable to establish a DB connection');
mysqli_query($link, "SET names UTF8");
// function temp() {
    $patient = mysqli_fetch_assoc(mysqli_query($link, "SELECT name,dob FROM patients WHERE id='69'"));
    echo $patient['name'];
// }
// temp();
?>
It works, and the patient's name is displayed.
What is going on here?
 
     
     
    