dynamic variables binding in mysqli bind_param

前端 未结 2 1327
南方客
南方客 2021-01-14 08:04

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         


        
2条回答
  •  爱一瞬间的悲伤
    2021-01-14 08:51

    $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);
    

提交回复
热议问题