I'm trying to search a MySQL database using PDO prepared statements as such...
try
{
// Prepare PDO Statement
$stmt = $readdb->prepare("SELECT * FROM athletes WHERE :search LIKE :term");
// Bind
$stmt->bindValue(':search', $search);
$stmt->bindValue(':term', '%' . $term . '%');
// Execute
$stmt->execute();
}
...this produces no error, however also returns no results.
For comparison sake, if I bypass binding by directly inserting my variables into the statement, it does work...
try
{
// Prepare PDO Statement
$stmt = $readdb->prepare("SELECT * FROM athletes WHERE $search LIKE '%$term%' ");
// Execute
$stmt->execute();
}
...but that obviously is a big security hole.
I'm almost certain this is some kind of syntax mistake I'm making, but after spending over two hours on it, I'm hoping fresh eyes may help.
Is there anything glaringly obvious I'm missing here? Thanks much, Stack!