正在自学看lamp兄弟连教程,不知道怎么回事按照教程我插入数据怎么也不成功,插入的是?0 0 ?$mysqli =new mysqli('localhost','root','','xsphpdb');
$stmt = $mysqli->stmt_init();//准备好一条语句放到服务器中,插入语句
$sql = "insert into shops(name,price,num,desn) values ('?','?','?','?')";
$stmt->prepare($sql);
//给站位符号每个?号传值(绑定参数) i d s b
$stmt->bind_param("sdis",$name,$price,$num,$desn);
$name = 'zhansan';
$price = '56.79';
$num =  '66';
$desn = 'hello world';
//执行$stmt->execute();
$name = 'lisi';
$price = '56.79';
$num =  '66';
$desn = 'haaa';
//执行$stmt->execute();
$name = 'wangwu';
$price = '56.79';
$num =  '66';
$desn = 'hbbbbb';
//执行$stmt->execute();
$name = 'zhaoliu';
$price = '56.79';
$num =  '66';
$desn = 'cccccc';
//执行$stmt->execute();echo '最后id'.$stmt->insert_id.'<br>';
echo '影响了'.$stmt->affected_rows.'行<br>';$stmt->close();Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement 

解决方案 »

  1.   

    Number of variables doesn't match number of parameters in prepared statement
    参数数量和变量的数量不相同。
      

  2.   

    Description
    Procedural style:bool mysqli_stmt_bind_param ( mysqli_stmt stmt, string types, mixed &var1 [, mixed &...] )
    Object oriented style (method):class mysqli_stmt { bool bind_param ( string types, mixed &var1 [, mixed &...] )}
    mysqli_stmt_bind_param() is used to bind variables for the parameter ers in the SQL statement that was passed to mysqli_prepare(). The string types contains one or more characters which specify the types for the corresponding bind variables 表格 1. Type specification charsCharacter Description 
    i corresponding variable has type integer 
    d corresponding variable has type double 
    s corresponding variable has type string 
    b corresponding variable is a blob and will be send in packages 
    这是手册上的解释。