A query is code

SQL injection happens when user input changes the structure of a database query. If an application builds SQL by joining strings, an input that looks like data can act like code.

The fix is structural

Use prepared statements with bound parameters. In PDO, that means placeholders such as :email and binding the value separately. Escaping a string is not a substitute for fixing the query structure.

Add sensible layers

Use a least-privilege database account, validate input on the server, avoid leaking database errors and monitor unusual query activity. These layers reduce impact, but the prepared statement is the primary control.

Validate the fix

Retest the affected endpoint with the same conditions that exposed the issue. A code change that has not been tested is only a hoped-for fix.