$ControlColumns = array("col1", "col2", "col3", "col4", "col5"); $params = array(); $cols = array(); $colnames = array_column($ControlColumns, 1); $bindtypes = "sssss"; foreach ($colnames as $col) { $params[] = &$cols[$col]; } $result = mysqli_stmt_bind_param($stmt, $bindtypes, $params);
Here’s the error:
Number of elements in type definition string doesn’t match number of bind variables in E:\XAMPP\xampp\htdocs\PHPTest\insert.php
And assume that the $stmt is a perfectly prepared statement with multiple parameters. In other words, it works fine.
Give up?
I guess I’m just stupid, but it took me an hour of messing around before I finally remembered that mysqli_stmt_bind_param was not designed to take an array input.
Use call_user_func_array to call that function instead. Remember to reference the variables.
$params = array(); $params[] = $stmt; $params[] = &$bindtype; $result = call_user_func_array('mysqli_stmt_bind_param', $params);