Encoding strings for PHP/SQL

could someone please tell me which characters need to be encoded for PHP and SQL, and how to do it?

data = “funny&%?_characters”;
safedata = escape(data);

I thought Flash automatically url encodes everything it sends out…?