Advertisement

10.28.2007 at 10:50AM PDT, ID: 22923158 | Points: 250
[x]
Attachment Details

Multiple bind_param() statements on one prepared statement?

Asked by movefiles in PHP and Databases, PHP Scripting Language, MySQL Server

Tags: , ,

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_param('s', $this->filePath);
//binding for second optional parameter
$fileHandlerQuery->bind_param('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
[+][-]10.28.2007 at 01:53PM PDT, ID: 20166320

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.28.2007 at 02:29PM PDT, ID: 20166412

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.28.2007 at 03:15PM PDT, ID: 20166513

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.28.2007 at 06:09PM PDT, ID: 20167038

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.29.2007 at 12:54AM PDT, ID: 20168030

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628