Your advice is really wrong.
mysql_real_escape_string() will not work for dynamic table names; it is intended to exclude string data limited only by quotation marks. He will not escape the inverse symbol. This is a small but important difference.
So I could insert an SQL injection into this, I just had to use a closing backtick.
PDO does not provide sanitation for dynamic table names, either .
This is why it is good not to use dynamic table names or, if necessary, compare them with a list of valid values, for example, a list of tables from the SHOW TABLES command.
I also did not know about this and was probably to blame for repeating the same bad advice until it was pointed out to me here on SO, also by Colonel Shrapnel.
Pekka μ Apr 27 '11 at 23:19 2011-04-27 23:19
source share