I copied a seemingly simple database connect function from one file to another and now it won't work. It's driving me a little mad:

function database_connect(){
    //connection to the database
    $dbhandle = mysqli_connect($hostname, $username, $password,$db_name) or die ("Unable to connect to MySQL");
    return $dbhandle;       
function get_row($id){
global $db;
$query = "SELECT * FROM users WHERE userID='".$id."'";
$result = mysqli_query($db, $query);
  if (mysqli_num_rows($result) > 0) {
     // create a variable for each item
     $row = mysqli_fetch_object($result);
     $first = $row->first;
     $last  = $row->last;
     $email = $row->email;

$db = database_connect();
get_row(1); //get a test user with id of 1
echo "Hello".$first;

 2 条回答