[nycphp-talk] Calling mysqli_stmt_bind_param with arbitrary number of parameters?

Daniel Krook krook at
Tue Feb 21 19:42:57 EST 2006

Hello all,

I'm trying to send parameters to a prepared statement using the mysqli 

The manual shows that it is used like this:
  $stmt = $mysqli->prepare("INSERT INTO CountryLanguage VALUES (?, ?, ?, 
  $stmt->bind_param('sssd', $code, $language, $official, $percent);

Where bind_param can take any number of values like so:
  $stmt->bind_param('s', $foo);
  $stmt->bind_param('si', $foo, $bar);
  $stmt->bind_param('sid', $foo, $bar, $baz); 
Unfortunately, I can't be sure of the number of placeholders in the SQL 
statement I am sending, and don't know how many corresponding parameters 
are in an array I pass to my function.  I would like to replicate this 
functionality that I use in the Unified ODBC extension:
  $stmt = odbc_prepare($db, $sql);
  $result = odbc_execute($stmt, $params); 
With bind_param it would seem I'd have to construct the bind_param call 
manually and then eval() it to get the same flexibility.  This is what I'd 
like to be able to do:
  $stmt->bind_param($aSeriesOfLettersDependingOnParamsSize, $params);

This would seem like something I'd need to do but haven't been able to 
figure out how to pull it off:
  eval(sprintf('$stmt->bind_param("sss...", %s, %s, %s, ...);') $params);
Is there a solution to this that anyone has run into?  Am I overlooking 
something really obvious (anytime eval() comes into play I get that 


Daniel Krook, Content Tools Developer
Global Production Services - Tools,

More information about the talk mailing list