不确定我在这里缺少什么,但我不断收到错误。
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);
答案 0 :(得分:1)
您不能使用短划线作为参数名称的一部分(我认为这是为了保持与this post的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);
答案 1 :(得分:1)
使用_
(下划线)代替连字符。
$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)");