PHP contains filters for a reason. They are there to protect you.
While this was a clever challenge, in general you should sanitize all of your input using filters.
While this was a clever challenge, in general you should sanitize all of your input using filters.
You should escape output.
In this case there isn't anything wrong with the input, and you can't say that any byte of MD5 is wrong or dangerous.
It's just data that is used improperly.
Binary data in SQL queries is especially tricky, because strings may be expected to be in specific character encoding (e.g. UTF-8), so you either need to use prepared statements and pass argument explicitly as binary, or use string-safe escaping (e.g. hex).
Input sanitisation has been solved thousands of times by people smarter than you. Do not reinvent the wheel (poorly).