Jump to content

[SOLVED] Displaying an array in a prepared statement


skyer2000

Recommended Posts

I'm working with prepared statements and need an array to be formatted in a certain way automatically.

 

Lets say I've got $testarray, with varying amounts of parameters.

 

I need to get this displayed as:

 

mysqli_stmt_bind_param($stmt, 'sssss', $testarray[1],$testarray[2],$testarray[3],$testarray[4],$testarray[5]);

 

How can I do this? The following will not work:

 

$foo = $testarray[1],$testarray[2],$testarray[3],$testarray[4],$testarray[5];

mysqli_stmt_bind_param($stmt, 'sssss', $foo);

 

Any ideas?

single quotes do not evaluate you mean, and yes I already know that.. my aim was to get it to be literal

 

xx,xx,xx,xx

 

since they are variables I did not want the variables evaluating.. then in the eval I evaluate the variable once, so that it places the string

 

$xx,$xx,$xx,$xx

 

inside the function, then the eval() will evaluate the function with the now in place variables

Unfortunately the eval() did not work, so I continued to look around and actually stumbled on the answer:

 

$types = str_repeat('s', count($bind_params));
array_unshift($bind_params, $types);
array_unshift($bind_params, $stmt);
call_user_func_array('mysqli_stmt_bind_param', $bind_params); 

 

(where $bind_params is the array of data)

 

Works great and is very flexible!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.