When I try to below code it give me a warning
mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables $stmt = $mysqli->prepare('SELECT * FROM users WHERE lname = ? AND fname = ?'); $type = "ss"; $param = array("Maq","bool"); $params[] = &$type; $params[] = &$param; call_user_func_array( array($stmt, 'bind_param'), $params );
I really don’t know why its happening I read a lot of same title questions in Stack Overflow but some has comma separated types or need more type but in my case I think its proper but why I am keep getting warnings?
Advertisement
Answer
$stmt = $mysqli->prepare('SELECT * FROM users WHERE lname = ? AND fname = ?'); $stmt->bind_param('ss', $param[0], $param[1]); $stmt->execute(); //other version $stmt = $mysqli->prepare('SELECT * FROM users WHERE lname = ? AND fname = ?'); $type = "ss"; $names = array("Maq", "bool"); $params = array(&$type, &$names[0], &$names[1]); call_user_func_array(array($stmt, 'bind_param'), $params);