So I have the following
public function search($table, $column, $term, $limit = 5){
$command = "SELECT name FROM `$table` WHERE `:col` LIKE :term LIMIT :lim";
$query = $this->connection->prepare($command);
$query->execute(array(":term"=>"%{$term}%", ':lim'=>$limit, ':col' => $column));
print_r($query->fetchAll());
}
and the return value is
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''5'' at line 1
From the duplicate, I changed the execute to this
$command = "SELECT name FROM `$table` WHERE ? LIKE ? LIMIT ?";
...
$query->bindParam(1, $column, PDO::PARAM_STR);
$term = "%{$term}%";
$query->bindParam(2, $term, PDO::PARAM_STR);
$query->bindParam(3, $limit, PDO::PARAM_INT);
$query->execute();
And now I am getting this:
Array ( )
Is my limit now 0 or something? What's going on?