在阅读之前:我知道桌子太奇怪而且很长,需要规范化;但由于某种原因,这是我的数据库,我应该使用这个表!对于那个很抱歉! 保持简短: 我遇到以下异常:
带有消息'SQLSTATE [HY093]的异常'PDOException':无效 参数号:绑定变量数与数量不匹配 C:\ xampp \ htdocs \ FD \ includes \ helper.php中的标记:472堆栈跟踪:
0 C:\ xampp \ htdocs \ FD \ includes \ helper.php(472):PDOStatement-> execute(Array)#1
C:\ XAMPP \ htdocs中\ FD \ newHrForm.php(113): helperFunctions :: UpdateTableHrForms('112','dfsfdsfds', '3123213','dfdsf','','','','','','','','','','','', '3213123213','1','3213123','213123213','3213213','213123123', )#2 {main}
我保存数据的功能如下:
public static function UpdateTableHrForms(
$id,$dob_city,$dob_province,$dob_country,...)
{
$conn = new mysqlcon();
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "INSERT into `hr_forms` (`id`,`dob_city`,
`dob_province`,`dob_country`,...)
VALUES (:id,:dob_city,:dob_province,:dob_country,...)";
try {
if (helperFunctions::CheckidExistForms($id) == 0) {
$result = $conn->prepare($query);
$result->execute(array('id'=>$id,'dob_city'=>$dob_city,'dob_province'=>$dob_province,'dob_country'=>$dob_country));
$Msg = "<div style=\"text-align:center;\" class=\"alert alert-success\">
<strong>Tips! </strong>
Data is successfully saved to database.
<button class=\"close\" data-dismiss=\"alert\" type=\"button\">×</button>
</div>";
} else {
$Msg = "<div style=\"text-align:center;\" class=\"alert alert-error\">
<strong>Error! </strong>
This employee information is already existed in the system.
<button class=\"close\" data-dismiss=\"alert\" type=\"button\">×</button>
</div>";
}
} catch (Exception $e) {
$e->getMessage();
$Msg = $e; /* "<div style=\"text-align:center;\" class=\"alert alert-error\">
<strong>Error! </strong>
This employee information cannot save in the system.
<button class=\"close\" data-dismiss=\"alert\" type=\"button\">×</button>
</div>"; */
}
return $Msg;
}
当我替换insert方法的值时(在UpdateTableHrForms中使用错误提供给我的那个并在mysql中运行它;没有错误;但在PHP中它给了我错误;如果我能帮助我吗?做错了什么?)
答案 0 :(得分:2)
您传递给execute
的数组格式不正确;你需要在参数名称的开头加上冒号。
应该是:
array(':id'=>$id,':dob_city'=>....