Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #8678

Re: mysqli_stmt_bind_param with multiple parameters in an array

From "M. Strobel" <sorry_no_mail_here@nowhere.dee>
Newsgroups comp.lang.php
Subject Re: mysqli_stmt_bind_param with multiple parameters in an array
Date 2013-03-16 12:39 +0100
Message-ID <aqj40aF6pqsU1@mid.uni-berlin.de> (permalink)
References <3b9ec35e-f117-41e3-8411-59bb81b0e9d7@googlegroups.com>

Show all headers | View raw


Am 16.03.2013 01:47, schrieb burrowingowl@gmail.com:
> 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_following,author_1_last_name,author_1_middle,author_1_preceding,author_1_role,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 ...
> 

Look up working examples of mysqli_stmt_bind_param() on the net. The & operator is
of limited use in modern PHP, use only if your code does not work without it.

And you should ask yourself how you came to believe you could put an array where
individual variables are needed.

/Str.

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

mysqli_stmt_bind_param with multiple parameters in an array burrowingowl@gmail.com - 2013-03-15 17:47 -0700
  Re: mysqli_stmt_bind_param with multiple parameters in an array Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-15 22:45 -0400
  Re: mysqli_stmt_bind_param with multiple parameters in an array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-16 12:39 +0100
  Re: mysqli_stmt_bind_param with multiple parameters in an array Chris Cosner <burrowingowl@gmail.com> - 2013-03-16 08:46 -0700
    Re: mysqli_stmt_bind_param with multiple parameters in an array Jerry Stuckle <jstucklex@attglobal.net> - 2013-03-16 11:58 -0400
    Re: mysqli_stmt_bind_param with multiple parameters in an array "Peter H. Coffin" <hellsop@ninehells.com> - 2013-03-16 11:51 -0500
    Re: mysqli_stmt_bind_param with multiple parameters in an array "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2013-03-16 18:04 +0100
  Re: mysqli_stmt_bind_param with multiple parameters in an array Chris Cosner <burrowingowl@gmail.com> - 2013-03-16 11:42 -0700

csiph-web