How can the issue of using object of type mysqli_result as array be resolved in PHP?

Issue: The error "Cannot use object of type mysqli_result as array" occurs when trying to access the result set of a MySQL query using array syntax. To resolve this, you need to fetch the data from the mysqli_result object using appropriate methods like mysqli_fetch_assoc(), mysqli_fetch_array(), or mysqli_fetch_row().

// Connect to the database
$conn = new mysqli($servername, $username, $password, $dbname);

// Execute a query
$result = $conn->query("SELECT * FROM table");

// Fetch data from the result set using mysqli_fetch_assoc()
while ($row = $result->fetch_assoc()) {
    // Access data using associative array keys
    echo $row['column_name'];
}