This means that you cannot use unreliable values ββdirectly, for example. as the name of a column or table β or as a LIMIT parameter.
For example, it is safe:
$query = "SELECT * FROM tbl WHERE col = ?";
while this is not so:
$query = 'SELECT * FROM tbl WHERE col = ? LIMIT ' . $_GET['limit']; $query = 'SELECT * FROM tbl WHERE ' . $_GET['field'] . ' = ?'; $query = "SELECT * FROM tbl WHERE col = ? AND othercol = '" . $_GET['other'] . "'"; $query = 'SELECT * FROM ' . $_GET['table'] . ' WHERE col = ?';
Basically, prepared statement placeholders are intended to be used where you would use the escaped value in single quotes in a classic query.
In case you are wondering why databases usually do not support placeholders for things like table names: in addition to the fact that dynamic table and column names are not common, the database engine usually optimizes the prepared statement when preparing it. This, however, cannot be done correctly without knowing which tables / columns are available.
source share