How can PHP developers ensure that the correct id number is displayed instead of $row->id in their code?

When displaying the id number from a database query result in PHP, developers should ensure that they are accessing the correct column name from the fetched row. If the column name is 'id', then developers can use $row->id to display the id number. However, if the column name is different, developers should use the correct column name to display the id number.

// Assuming the column name for id is 'user_id'
// Fetching data from the database
$query = "SELECT user_id FROM users WHERE id = 1";
$result = $conn->query($query);

// Displaying the correct id number
while($row = $result->fetch_object()) {
    echo $row->user_id;
}