mysql_real_escape_string ALONE can prevent nothing.
Moreover, this function has nothing to do with injections at all.
Whenever you need escaping, you need it despite of "security", but just because it is required by SQL syntax. And where you don't need it, escaping won't help you even a bit.
The usage of this function is simple: when you have to use a quoted string in the query, you have to escape it's contents. Not because of some imaginary "malicious users", but merely to escape these quotes that were used to delimit a string. This is extremely simple rule, yet extremely mistaken by PHP folks.
This is just syntax related function, not security related.
Depending on this function in security matters, believing that it will "secure your database against malicious users" WILL lead you to injection.
A conclusion that you can make yourself:
No, this function is not enough.
Prepared statements is not a silver bullet too. It covers your back for only half of possible cases. See the important addition I made to the famous question for the details
mysql*is a dinosaur that should never be used. If so many "tutorial" sites didn't stubbornly continue to use it, the PHP dev team would've already deprecated it. New devotees to this backwards practice are minted daily because they don't know any better and after all, "the tutorial said I could do it this way." Prepared statements are the correct way to prevent SQL injection.mysqlidoes have an equivalent method: mysqli_real_escape_string. The thing is, the whole point of my comment is that you should use prepared statements, which negates the possibility of injection without the need for manual escaping. Take a look at the docs for mysqli::prepare for more info.