SQLSTATE[HY093]:找不到我缺少的东西,我需要一双新鲜的眼睛


SQLSTATE[HY093]: cant find what I'm missing, i need a fresh set of eyes

不确定我在这里错过了什么,但我不断收到错误。

SQLSTATE[HY093]:参数编号无效:未定义参数

$sth = $dbh->prepare("INSERT INTO time (student_id, super_id, d1-date, d2-date, d3-date, d4-date, d5-date, d1-hours, d2-hours, d3-hours, d4-hours, d5-hours) VALUES(:value-1,:value-2,:value-3,:value-4,:value-5,:value-6,:value-7,:value-8,:value-9,:value-10,:value-11,:value-12)");
    $pass = array
    (
        ':value-1'=>$user_id,
        ':value-2'=>$super_id,
        ':value-3'=>$data_array[0][0],
        ':value-4'=>$data_array[0][1],
        ':value-5'=>$data_array[0][2],
        ':value-6'=>$data_array[0][3],
        ':value-7'=>$data_array[0][4],
        ':value-8'=>$data_array[1][0],
        ':value-9'=>$data_array[1][1],
        ':value-10'=>$data_array[1][2],
        ':value-11'=>$data_array[1][3],
        ':value-12'=>$data_array[1][4]
    );
    $sth->execute($pass);

使用_(下划线)而不是连字符。

$sth = $dbh->prepare("INSERT INTO `time` (`student_id`, `super_id`, `d1-date`, `d2-date`, 
      `d3-date`, `d4-date`, `d5-date`, `d1-hours`, `d2-hours`, `d3-hours`, `d4-hours`, 
       `d5-hours`) 
       VALUES(:value_1,:value_2,:value_3,:value_4,:value_5,:value_6,:value_7,
       :value_8,:value_9,:value_10,:value_11,:value_12)");

您不能使用破折号作为参数名称的一部分(我认为这是为了根据这篇文章保持与 Oracle 的兼容性)。

也许像这样:

    $sth = $dbh->prepare("INSERT INTO time (student_id, super_id, d1-date, d2-date, d3-date, d4-date, d5-date, d1-hours, d2-hours, d3-hours, d4-hours, d5-hours) VALUES (:value1,:value2,:value3,:value4,:value5,:value6,:value7,:value8,:value9,:value10,:value11,:value12)");
    $pass = array
    (
        ':value1'=>$user_id,
        ':value2'=>$super_id,
        ':value3'=>$data_array[0][0],
        ':value4'=>$data_array[0][1],
        ':value5'=>$data_array[0][2],
        ':value6'=>$data_array[0][3],
        ':value7'=>$data_array[0][4],
        ':value8'=>$data_array[1][0],
        ':value9'=>$data_array[1][1],
        ':value10'=>$data_array[1][2],
        ':value11'=>$data_array[1][3],
        ':value12'=>$data_array[1][4]
    );
    $sth->execute($pass);