当我尝试下面的代码时,它给了我一个警告
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 );
我真的不知道为什么会发生这种情况我在 Stack Overflow 中阅读了很多相同标题的问题,但有些问题有逗号分隔类型或需要更多类型,但在我的情况下,我认为这是正确的,但为什么我不断收到警告? 最佳答案
$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);
关于php - mysqli bind_param 中的动态变量绑定(bind),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27961401/