[mysql]SQLSTATE [HY093]: 无效的参数数目︰ 绑定的变量数目与标记错误号不匹配

标签: sql MySQL PHP
发布时间: 2017/4/9 23:20:45
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我有此错误 2 我的页面上,我不明白为什么。我已经重写代码和三重检查过,但我找不到有什么不对。

第一个问题是︰

 public function academics ($id,$problem_solving ,  $math_understanding,      $cs_understanding ,   $math_useful ,  $cs_useful, $math_ava,  $cs_ava,    $assigment_start,   $assigment_submit,  $travel_time,   $stress,$assigment_when,    $full_part,     $pair_programming,  $attending_class,   $attending_labs,$attending_tutorials,   $extra_reading, $p_progamming,  $q_cs,  $q_maths,   $procrastinating_assigments,    $procrastinating_studying){
    try{
        $stmt = $this->db->prepare("UPDATE student_data SET problem_solving=:problemS, math_understanding=:math_U, cs_understanding=: cs_u, math_useful =:m, cs_useful=:cs_u, math_ava=:ma, cs_ava=:ca, assigment_start=:ass_st, assigment_submit=:assigment_submit, travel_time =:travel_time, stress=: stress, assigment_when =:assigment_when, full_part =:full_part, pair_programming=: pair_programming,   attending_class=: attending_class, attending_labs=: attending_labs, attending_tutorials =:attending_tutorials, extra_reading =:extra_reading, p_progamming=: p_progamming,  q_cs=: q_cs,    q_maths=: q_maths, procrastinating_assigments=:procrastinating_assigments, procrastinating_studying=:procrastinating_studying WHERE user_id=:uid");
        $stmt->bindparam(":uid", $id);
        $stmt->bindparam(":problemS",$problem_solving );
        $stmt->bindparam(":math_U",$math_understanding);
        $stmt->bindparam(":cs_u",$cs_understanding );
        $stmt->bindparam(":m",$math_useful );
        $stmt->bindparam(":cs_u",$cs_useful);
        $stmt->bindparam(":ma",$math_ava);
        $stmt->bindparam(":ca",$cs_ava);
        $stmt->bindparam(":ass_st",$assigment_start);
        $stmt->bindparam(":assigment_submit",$assigment_submit);
        $stmt->bindparam(":travel_time",$travel_time);
        $stmt->bindparam(":stress",$stress);
        $stmt->bindparam(":assigment_when",$assigment_when);
        $stmt->bindparam(":full_part",$full_part    );
        $stmt->bindparam(":pair_programming",$pair_programming);
        $stmt->bindparam(":attending_class",$attending_class);
        $stmt->bindparam(":attending_labs",$attending_labs);
        $stmt->bindparam(":attending_tutorials",$attending_tutorials);
        $stmt->bindparam(":extra_reading",$extra_reading);
        $stmt->bindparam(":p_progamming",$p_progamming);
        $stmt->bindparam(":q_cs",$q_cs);
        $stmt->bindparam(":q_maths",$q_maths);
        $stmt->bindparam(":procrastinating_assigments",$procrastinating_assigments);
        $stmt->bindparam(":procrastinating_studying",$procrastinating_studying);
        $stmt->execute(); 
    } catch(PDOException $e)
    {
        echo $e->getMessage();
    }  
}

第二个是︰

public function comps ($id,$long,$often_comp,$gaming,$research,$doc,$music,$vid,$fix,$social){
    try{
        $stmt = $this->db->prepare("UPDATE student_data SET long=:long, often_comp=:often , gaming=:gaming, research=:research, doc=:doc, music=:music, vid=:vid, fix=:fix, social=:social  WHERE user_id=:uid");
        $stmt->bindparam(":uid",$id);
        $stmt->bindparam(":long",$long);
        $stmt->bindparam(":often",$often_comp);
        $stmt->bindparam(":gaming",$gaming);
        $stmt->bindparam(":research",$research);
        $stmt->bindparam(":doc",$doc);
        $stmt->bindparam(":music",$music);
        $stmt->bindparam(":vid",$vid);
        $stmt->bindparam(":fix",$fix);
        $stmt->bindparam(":social",$social);
        $stmt->execute(); 
    } catch(PDOException $e)
    {
        echo $e->getMessage();
    }  
}

解决方法 1:

好吧,这是太长的注释 (没有双关意在那"长"顺便说一句)。

看,如果那些是不是错别字 (我希望他们不是),你有不少的冒号后面有空格的绑定。

您需要为他们删除空格和也裹 MySQL 保留字在滴答声中被 LONG ,或将它重命名为不是保留字。

SET `long`=:long, ...

参考︰


脚注︰

TBH︰ 我没有料到你所有的绑定,所以如果我错过了一些东西,你需要看一遍所有并确保它们都匹配。


编辑︰

"我并不知道 php,以为它的空间计数忽略他们像 C/c + +,现在的作品。谢谢你再次!!— — 士"

  • 这不是 C/c + +,这是 PHP 空间做计数在该语言中。
官方微信
官方QQ群
31647020