PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi I have an infuriating problem which is stalling me with two large projects for a well known NGO right now.
I am using mysqli and bound variables where the number of variables to bind is dependent on user input. I have a version of the code below working in php 5.2 but as of php 5.3 this method is no longer valid, specifically due to a change in the behavior of call_user_func_array with bound variables as arrays. I have read about this problem eslewhere but cannot get any of the workarounds to work with my example. Any help would be greatly appreciated.
# $parts is an array with variable number of values
# $type is an array with variable number of values
# $params is an array with variable number of values
$query = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT
taxon.TaxonID,
FROM taxon
WHERE'
. join('', $parts) .
" ORDER BY taxon.TaxonID";
# Prepare stmt
if ($stmt = $mysqli->prepare($query)) {
call_user_func_array (array($stmt, 'bind_param'),array_merge(array(join('', $type)), $params));
# execute
$stmt->execute();
# bug info
echo $stmt->errno, ':', $stmt->error;
#store result
$stmt->store_result();
# bind results
$stmt->bind_result($ID);
# fetch values
while ($stmt->fetch()) {
# results code goes here!
}
# free memory
$stmt->free_result();
# close statement
$stmt->close();
}
Last edited by darwin_tech on Mon Jan 10, 2011 8:16 am, edited 1 time in total.