That's a good and very logical question. Indeed, why would we need a connection for a trifle string manipulation - adding slashes to certain characters?
All this hassle is about the character set.
$link contains a mysqli connection. And mysqli connection contains the information about current charset. And this information is required to escape the string properly, depends on charset. So indeed the result will be different for some different (though quite odd) character sets.
A different returned value example can be found in this answer.
This is why mysqli_real_escape_string()
does no good by itself, but should be always used after setting the proper charset through mysqli::set_charset()
On a side note I must say that this function is rather obsoleted whatsoever. Instead of manual escaping one should use prepared statements (and, given with mysqli this this mechanism is one big WTF, it is hugely recommended to use PDO).