What are common errors that result in the output "Resource id #X" when fetching data from a database in PHP?

When fetching data from a database in PHP, the "Resource id #X" output typically occurs when the result of the database query is not being properly handled or accessed. This error usually happens when trying to output the result directly without fetching the data from the resource object. To fix this issue, you need to fetch the data from the resource object using functions like `mysqli_fetch_assoc()`, `mysqli_fetch_array()`, or `mysqli_fetch_row()`.

// Assuming $conn is your database connection and $query is your SQL query

$result = mysqli_query($conn, $query);

if ($result) {
    while ($row = mysqli_fetch_assoc($result)) {
        // Process the data here
        echo $row['column_name'];
    }
} else {
    echo "Error: " . mysqli_error($conn);
}