0

I am currently working to switch over a site using mysql functions to mysqli. The Select query's where clause ends up being built dynamically depending on user choices. My understanding is mysqli_bind_param needs the exact number of parameters, so do I need to use programming logic to build the prepare statement dynamically or is there any easier way using the prepared statements with mysqli?

Kara
  • 5,650
  • 15
  • 48
  • 55
arvinkx
  • 134
  • 1
  • 10
  • 2
    There are many ways to deal with this problem. A common one is just switching to PDO so that you don't have to do anything *weird*. Have you reviewed [the high-voted notes on the `mysqli_stmt::bind_param` manual page](http://php.net/mysqli-stmt.bind-param.php)? For possible dupes here on SO, search for "[mysqli bind_param dynamic](http://stackoverflow.com/search?q=mysqli+bind_param+dynamic)". – Charles May 04 '14 at 01:42
  • Thanks for the resources, I will look into them and PDO as well. – arvinkx May 04 '14 at 15:05
  • +1 I agree PDO is way easier for the case when you have a variable number of parameters. You can simply pass an array of values to `PDOStatement::execute()`. Mysqli requires using `call_user_func_array()` which is confusing and hard to get right. – Bill Karwin May 06 '14 at 18:12
  • PDO is actually the route I ended up taking. I spent a little extra time learning to use PDO (which was not much) but well worth it, made dealing with this problem much easier. Thanks again all. – arvinkx May 06 '14 at 22:10

0 Answers0