Hi All,

I been stuck on a problem for a bit now and cant really find an answer so I hope someone knows here.

I have the following code:
PHP Code:
function db_query_prepare($dbh$sql$args) {

   
$dbst mysqli_prepare($dbh$sql);
   if(!
$dbst) {return 0;}
   
   foreach(
$args as $arg) {
     
mysqli_stmt_bind_param($dbst"i"$arg);
   }

   
mysqli_stmt_execute($dbst);
   
mysqli_stmt_store_result($dbst);

   return 
$dbst;
}

$result db_query_prepare($db"SELECT firstname FROM profile WHERE profileID = ? AND statusID = ? LIMIT 1", array(553)); 
the above was taken from the book: php cookbook2
(For now assume all values are integers)

I have code very similar to the that above, my question is simple, is this code correct? I can get the code to work with a single ? (placeholder), but it throws a "Number of variables doesn't match number of parameters in prepared statement in .." warning/error, I know there is a form of the function that is as follows:

PHP Code:
mysqli_stmt_bind_param($dbst'ii'5554 
But my problem is I may not know the parameters in advance so I just want to pass db_query_prepare the sql and needed values in an array? looking at the above code taken from the book implies that it indeed can be done, but I just get the same error, I have also tried implode, to return a string 1,2,3 etc, but still I get the above error?

I have done a bit of searching, and there are reported bugs giving the same error, but I have upgraded libraries as suggested but still to no avail?

MySqli details:
Client version: 50045
Server version: 50041

The only solution I have found is to build a string and execute it using eval!