Prepared statements use placeholders for the values ββto be inserted. The code snippet in your question already interpolates the value in the query and is therefore subject to SQL injection.
The following pseudo-code highlights prepared statements:
$stmt = $conn->prepare('SELECT * FROM `table` WHERE `id` = ?'); $stmt->execute($_POST['id']);
In this example, the logic of this "code" will take care of correctly quoting what is in $_POST['id'] , and substituting a question mark ? in it. You may also encounter the following placeholders:
$stmt = $conn->prepare('SELECT * FROM `table` WHERE `id` = :id'); $stmt->execute(array( 'id' => $_POST['id'] ));
Please note, however, that the prepared statements do not relieve you of the obligation to check the user input provided before passing it to the (My) SQL statement: if id expected to be integer, only accept integers as input.
source share