What is the common error message "mysql_fetch_assoc() expects 1 to be resource, boolean given" in PHP and how can it be resolved?

The common error message "mysql_fetch_assoc() expects 1 to be resource, boolean given" in PHP occurs when the query executed in MySQL returns a boolean value (true or false) instead of a resource. This error can be resolved by checking if the query execution was successful before trying to fetch data. This can be done by verifying the return value of the query function (e.g., mysqli_query()).

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

if($result){
    while($row = mysqli_fetch_assoc($result)){
        // Process the fetched data
    }
} else {
    // Handle the query execution failure
}