2.Bind using pdo

# $pdo already generated above
$sql = "SELECT p.id FROM products p WHERE p.name =: p.name";// error due to: p.name
$stmt = $pdo->prepare ($sql);
$stmt->bindValue (': p.name', 'Test product', '2');
$stmt->execute ();
# fetch results with fetch

It works if you set WHERE p.name =: name in the SQL statement
: p.name, please tell me how to escape

  • Answer # 1

    I can't find it in the official manual
    The only placeholders you can use with named placeholders are "alphanumeric characters, underscores" only
    Switch to the question mark placeholder if you really don't like it

  • Answer # 2

    For the same reason you can't use periods in php variable names
    I think you can't include a period in the placeholder name.
    The evidence is being investigated.

    Note that the rules for naming variables (not just placeholders) are
    PHP: Basics-Manual
    It is in.