I just came across this problem:
How can I use this:
call_user_func_array('mysqli_stmt_bind_param', array_merge(array($stmt, $type), $params));
in OO style?
like that (code didn't work for me):
call_user_func_array($stmt->bind_param, array_unshift($params, $type));
example where it could be useful (works, but is mixture of styles):
$params[] = 'value';
$params[] = 'anotherValue';
// ...
$sql = 'SELECT myField1, myField2 FROM mytable WHERE myField1 = ?';
$type = 's';
for ($ic = 0, $ub = count($params) - 1; $ic < $ub; $ic++) {
$sql .= ' AND myField1 = ?';
$type .= 's';
}
echo 'sql=' . $sql . '<br />' . 'type=' . $type;
$conn = new mysqli($host, $user, $pwd, $db);
$stmt = $conn->prepare($sql);
// couldn't get the following to run with object-oriented style. Nice mixture ain't it? Any suggestions, anyone?
call_user_func_array('mysqli_stmt_bind_param', array_merge(array($stmt, $type), $params));
$stmt->execute();
$stmt->bind_result($fld1, $fld2);
while($stmt->fetch()){
echo '<br />' . 'myField1: ' . $fld1 . ', myField2: ' . $fld2. ';
}