I had this discussion with a high reputation PHP guy:
PDO has no use here. as well as mysql_real_escape_string. extremely poor quality.
In order to answer how to actually fix the code:
'...FROM `' . str_replace('`', '``', $tableName) . '`...'
This duplicates all backticks in the table name (this is how escaping in MySQL is done).
One thing I'm not sure about, is whether this is "encoding-safe" (how does one call it correctly?). One typically recommends mysql_real_escape_string instead of addslashes, because the former takes the encoding of the MySQL connection into account. Maybe this problem applies here, too.