Successful or Error Message after running mysql code in functions.php

From the Codex page for $wpdb:

The function [$wpdb->query] returns an integer corresponding to the number of rows affected/selected. If there is a MySQL error, the function will return FALSE.

So in order to display a success/failure message, it should be a simple matter:

$result = $wpdb->query( "
    DELETE FROM $wpdb->posts
    WHERE anything = 'whocares'
" );

if( FALSE === $result ) {
    echo( "Failed!" );
} else {
    echo( "Great success!" );
}