added real_escape_string to some functions