NYCPHP Meetup

NYPHP.org

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

Daniel Convissor danielc at analysisandsolutions.com
Tue Feb 21 22:38:03 EST 2006


On Tue, Feb 21, 2006 at 04:42:57PM -0800, Daniel Krook wrote:
>  
> 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.

Here's something I just did along these lines the other day for the Single 
Sign-On module I just contributed to Drupal.  (Note that Drupal's 
db_query() function takes the SQL string as the first parameter and an 
unlimited number of parameter values as subsequent parameters.)

$in   = substr(str_repeat("'%s',", count($sids)), 0, -1);
$sql  = "UPDATE sessions SET uid = %d WHERE sid IN ($in)";
$args = array_merge(array($sql), array($user->uid), $sids);

call_user_func_array('db_query', $args);

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list