Jump to content

prepared statement problem


jimfog

Recommended Posts

I have the following query

SELECT * from holidays WHERE holid_date >=(?)and holid_date <=(?)'

I just want to select a range of dates from a table between the two dates given(beg_date and end_date)

Here is some code related to the prepared statement I try to use for it:

 $stmt->bind_param('ss',$beg_date,$end_date);          $stmt->execute();         $stmt->bind_result($dates);         $stmt->fetch();

trying to run the above I get this error:

 

Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement in C:Apache24htdocsAppointmentsAdministratoradmin_db_code.php on line 398

 

I assume I get this error cause a range of values get passed to dates....anyway...how can I write a prepared statement for such a query...I use mysqli.

 

 

Link to comment
Share on other sites

That's only going to work if the table has 1 column. You're selecting all columns but then you only give 1 variable for the results. Each column needs a variable, and you should list the columns you want to select to avoid having your code break if the database structure changes.

Link to comment
Share on other sites

That's only going to work if the table has 1 column. You're selecting all columns but then you only give 1 variable for the results. Each column needs a variable, and you should list the columns you want to select to avoid having your code break if the database structure changes.

you were right...instead I tried this....

SELECT holid_date from holidays WHERE holid_date >=(?)and holid_date <=(?)'

I specify a column...

 

The only problem is that instead of getting all the dates I should be getting(within the interval specified by beg_date and end_date) I get only the first one.

 

probably the problem will be solved if I use a while loop...what do you think?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...