Hi, can i ask some help how can i do search using the LIKE operator in PDO.
here is my code but it’s not working
$strcon= $dbconn->prepare("SELECT employee_name
FROM employee where employee_name LIKE '%?%'
");
$strconn->bindParam(1,$querysearch);
$strconn->execute();
And remember that with bindparam(), you don’t want to have quotes around the parameter, because they’re added for you:
$strcon= $dbconn->prepare("SELECT employee_name
FROM employee where employee_name LIKE ?");
$strconn->bindParam(1,'%' . $querysearch . '%');
$strconn->execute();
If that doesn’t help, show more code AND define “doesn’t work” with a bit more detail please - do you get errors, or does it just not return anything?
$strcon= $dbconn->prepare(“SELECT employee_name
FROM employee where employee_name LIKE ?”);
$strconn->bindParam(1,‘%’ . $querysearch . ‘%’);
$strconn->execute();
This is the error.
error = “only variables can be passed by reference”;
I fixed it by changing it to this way.
$find = ‘%’ . $querysearch . ‘%’;
$strcon= $dbconn->prepare(“SELECT employee_name
FROM employee where employee_name LIKE ?”);
$strconn->bindParam(1,$find);
$strconn->execute();