I’m creating a form with a single search field and I want that field to query against 3 different sql columns (think album titles, track names, and artists).
This is the code that I’m trying to make work…
$search = "%".$_POST["sermon"]."%";
$stmt = $dbh->prepare("SELECT * FROM dbo.TblSermon WHERE (Series LIKE :search) OR (Sermon LIKE :search) OR (Speaker LIKE :search) ORDER BY Sermon ASC, Date ASC");
$stmt->bindParam(':search', $search);
$stmt->execute();
This is the error that I get…
SQLSTATE[07002]: [Microsoft][SQL Server Native Client 10.0]COUNT field incorrect or syntax error
From all the tutorial I’ve seen, placeholders aren’t meant to be used more than once (each field should have its own). Is there a way to get this to work?
JJ
Id jsut change the placeholder names to reflect the field youre searching. Then instead of calling bind params id just bind it all on execute.
If there are a ton of fields then it might be better to just define the array of placeholders and then use
array_fill_keysso you dont have to keep typing the same variable name over and over again for assignment into the array… of course at that point you could just loop over the array of placeholders and callbindParamwith the same value argument… either way.