Bind unknown number of parameters?

hi

What is the correct way to do a function like:


public function check_offers_available($db, $skills_user) {
		$arr_tags = array('16', '17', '36', '546');
		$z = implode(', ', array_fill(0, count($arr_tags), '?'));
		$str = implode('', array_fill(0, count($arr_tags),'s'));

		$par = "'" . implode("','", $arr_tags) . "'";
		
		$c_arr_tags = count($arr_tags);
		
		$sql = $db -> prepare("
			 SELECT offer_id_offer
  			 FROM offer_has_tags
  			 WHERE tags_id_tags IN ($z)
			 GROUP BY offer_id_offer
 			 HAVING COUNT(*) = ?
		");
			
		
		$sql -> bind_param("$str.'i'", $par, $c_arr_tags);
		$sql -> execute();
		$sql -> bind_result($id_offer);
		
		return $id_offer;
		
	}

At the moment i got:

Number of elements in type definition string doesn’t match number of bind variables

As far as I can guess without seeing your exact error message, the error is not about your function (check_offers_available) rather it is all about the param_bind of PDO. So check the param_bound. So I suspect the problem is:


$sql -> bind_param("$str.'i'", $par, $c_arr_tags);

Should be:


$sql -> bind_param($str . 'i', $par, $c_arr_tags);

If rest of the variables are having correct values, this fix should avoid the problem.

I need to use

call_user_func_array

thanks

Did it work without changing the above I said?

No. You are correct about “”.