Working function_epic_rules

use $wpdb instead of deprecated mysql func