2

Is there a way to bind one parameter at a time in a mysqli_stmt object? i.e. something like,

// $stmt is a mysqli_stmt object.
// $bindvals is an array.

foreach ($bindvals as $item){
    $stmt->bind_param('s',$item);
}

The above throws "Number of elements in type definition string doesn't match number of bind variables" (as long as count($bindvals)>1).

My ultimate goal in this particular case is to create a function that won't need to be edited whenever a column is added to a table, so something that will work for an indeterminate number of columns.

  • 2
    This is not possible. Start with http://stackoverflow.com/questions/5100046/how-to-bind-mysqli-bind-param-arguments-dynamically-in-php?noredirect=1&lq=1 Or move to PDO. – u_mulder Aug 05 '16 at 21:58
  • 1
    PDO works like this, why don't you use it instead of mysqli? – Barmar Aug 05 '16 at 22:22
  • PDO _might_ not be an option because we haven't used it in my office before. Regardless, I very much appreciate the information. For the moment, I'm going to do this statically and leave a comment saying that in the future we may want to refactor using PDO, as I don't really have time to wait for superiors to research PDO and tell me that I can or can't use it. –  Aug 08 '16 at 13:04

0 Answers0