This works for me:
function invites_ifreal($val)#check if it’s a real invite code
{global $wpdb;
$meta_key = ‘miles’;
$res = $wpdb->get_var( $wpdb->prepare(
“SELECT COUNT(*) FROM “.INVITES_PREFIX.”invites WHERE value= %d LIMIT 1”,addslashes(invites_unbeautify($val))));
if(is_null($res))
{
echo $wpdb->last_error;
return FALSE;
}
if(!$res)
return FALSE;
return TRUE;
}