FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » mysqli_stmt_bind_param with multiple parameters in an array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
mysqli_stmt_bind_param with multiple parameters in an array [message #180739] Sat, 16 March 2013 00:47 Go to previous message
burrowingowl is currently offline  burrowingowl
Messages: 3
Registered: March 2013
Karma:
Junior Member
Goal: Insert a row into a mysql table using mysqli and bound parameters.

$stmt = mysqli_prepare($dbhandle, "INSERT INTO work (".$SQL_fields.") VALUES
($SQL_params_text)");

This results in the following query, for example:
INSERT INTO work (abstract,announcement,apparatus_description,author_1_first_name,author_1_f ollowing,author_1_last_name,author_1_middle,author_1_preceding,author_1_rol e,author_2_first_name) VALUES(?,?,?,?,?,?,?,?,?,?)

This list has been truncated for testing purposes. In practice it will be over 100 fields, heavy on text.

$SQL_params_text is ?,?,?, with the number ? matching the number of fields.
$sqltypes is a string like 'ssssssssss'
The array $SQL_values holds the data.

I have tried
mysqli_stmt_bind_param($stmt,$sqltypes,$SQL_values);

and
$msbp = array( $stmt, $sqltypes, $SQL_values);
call_user_func_array( 'mysqli_stmt_bind_param', $msbp);

I have also tried the above while wrapping $SQL_values in
function fn_refValues($arr){
$refs = array();
foreach($arr as $key => $value){
$refs[$key] = &$arr[$key];
}
return $refs;
}

Without the wrapper I get:
> PHP Warning: mysqli_stmt_bind_param(): Number of elements in type definition string doesn't match number of bind variables in ...

This is not true. I've checked it several ways. It just doesn't like $SQL_values as a plain old array. Maybe it's counting the whole array as 1, vs. 10 items in the type definition string.

And with the wrapper to make the values into references I get:
> PHP Warning: Parameter 3 to mysqli_stmt_bind_param() expected to be a reference, value given in ...

Parameter three is fn_refValues($SQL_values) in this case.

Simple fix, or am I just going about this the wrong way?

Thanks.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: question about class getters
Next Topic: script works fine now
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Dec 19 17:48:12 GMT 2024

Total time taken to generate the page: 0.04404 seconds