mysql_real_escape_string escapes characters that are special regarding MySQL string literals:
\
, backspace character
'
, single quote character
"
, double quote character
\0
, NUL character
\n
, line break character
\r
, carriage return character
^Z
, Control-Z, substitute character
However, it handles any data equally regardless of what the input data is actually representing. mysql_real_escape_string
does only consider the character encoding in effect.
Regarding your concern: HTML, JavaScript and PHP are all interpreted languages and require an interpreter for interpretation/execution. As for HTML and JavaScript, it’s typically a web browser. And as for PHP, it’s typically the PHP runtime on a web server. But MySQL server can only interpret one language: the SQL dialect also known as MySQL.
This is also the reason why one wouldn’t handle other languages besides MySQL when inserting data into the database. Neither would one escape/encode/sanitize/insert-preferred-verb-here HTML, nor JavaScript, nor PHP, nor any other language besides MySQL.
You would only escape/encode/sanitize/insert-preferred-verb-here any of those languages when you hand the data down to a component that may interpret that specific language.