As long as you use mysqli_set_charset() to set the client encoding, and mysqli_real_escape_string() used to format only strings , this is absolutely safe.
However, if your question implies using this function directly in the application code, and not behind the scenes of processing the request based on the placeholder, or at least in the form of the PDO quote() -like function (which performs escaping and ), this is a direct injection method.
Not the problem itself is a problem, but how it is used:
- since this is only part of the necessary formatting, you can easily forget the other part and slip into trouble
- or even it can be easily used to format not a string, but another literal that would not be profitable from escaping at all.
- secondly, when it is used directly in the application code, the use becomes inconsistent or random, since there is no way to force the developer to format each literal properly and without fail. This can again lead to inaccuracies and injections.
To do this, you should always use the placeholder to represent the data in the query (while mysqli_real_escape_string can be used to process this placeholder)
Your common sense
source share