Building an API authentication layer in PHP. We are using PDO with prepared statements everywhere for user input.
Are parameterized prepared statements completely immune to SQL injection, or are there edge cases (like table names, order by clauses, or charset issues) where injection is still possible?
1. Identifiers cannot be parameterized: You cannot bind table names, column names, or
ASC/DESCkeywords. For dynamic columns, always use a strict whitelist:= ['created', 'likes', 'views']; = in_array(, ) ? : 'created';2. Emulated prepares & Charset: Make sure
PDO::ATTR_EMULATE_PREPARES => falseis disabled and always setcharset=utf8mb4in your DSN string.3. LIMIT clauses in older MySQL versions can sometimes misbehave if PDO sends them as strings instead of integers. Use
PDO::PARAM_INTexplicitly.ATTR_EMULATE_PREPARES. If emulation is on, PDO simulates prepares on the client side instead of using native database engine statement prepares. Disabling emulation is step #1 on any new project.