Not to beat a dead (or is it very living?) Horse, but ...
Injection can occur only when the data is read by the SQL machine in the form of commands. In a very simple case, if you allow characters without " in your data, and your data is encapsulated with characters " in SQL, they activated the SQL injection attack.
The key to preventing any SQL injection is to correctly check and delete incoming data EVERY time when it is included in the SQL statement. An easy way to do this is to simply use prepared statements that will take care of this for you, allowing you to safely pass parameters to the SQL statement.
Each database library has its own way of escaping or using prepared statements. In MySQL and PHP, you have mysqli_real_escape_string() , which should be used EVERY TIME PERIOD when you use the mysqli library.
The PDO library has its own path, but if I remember correctly, the prepared statements were a large part of the PDO - use them in 100% of cases, and you will be fine in this.
source share