I am building a search class that allows users to search for files on various optional parameters. Since the parameters are all optional I am trying to dynamically build the SQL statement and then call bind_param() for each parameter that needs to be bound. Before building the for statement to handle this I tried a static example that would essentially mimic what I was trying to do:
//SQL statement pieces together through a for loop running through the set parameters
$fileHandlerQuery = $this->mysqliObj->prepare(
"SELECT tbFile.name
FROM tbFile
WHERE tbFile.path=?
AND tbFile.siteId=?");
//binding for first optional parameter
$fileHandlerQuery->bind_pa
ram('s', $this->filePath);
//binding for second optional parameter
$fileHandlerQuery->bind_pa
ram('i', $this->siteId);
On each of the bind_param() calls I get the following error:
Warning: mysqli_stmt::bind_param() [function.mysqli-stmt-bind
-param
]: Number of variables doesn't match number of parameters in prepared statement in ...
It looks as though PHP won't let you incremently call bind_param() if the number of vars doesn't equal the number of question marks in the statement. I have to think there is an easy way around this but at the moment I'm a little stumped. Any ideas would be appreciated.
Thanks,
Steve
Start Free Trial