阅读之前:我知道这个表太奇怪太长,需要规范化;但出于某种原因,这是我的数据库,我应该使用这个表!对不起!为了简短起见:我收到以下异常:
异常"PDOException",消息为"SQLSTATE[HY093]":无效 参数编号:绑定变量的数量与 C:''xampp''htdocs''FD''include''helper.php:472 中的 tokens' 堆栈跟踪:
0 C:''xampp''htdocs''FD''include''helper.php(472): PDOStatement->execute(Array) #1
C:''xampp''htdocs''FD'ewHrForm.php(113): helperFunctions::UpdateTableHrForms('112', 'dfsfdsfds', "3123213", "DFDSF", ", ", ", ", ", '3213123213', '1', '3213123', '213123213', '3213213', '213123123', ) #2 {主要}
我的保存数据功能如下:
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;
}
当我替换我的插入方法的值(在 UpdateTableHrForms 中用错误给我的值并在 mysql 中运行它时;没有错误;但在 PHP 中它给了我错误;如果我做错了什么,你能帮帮我吗?
你传递给execute
的数组的格式不太正确;你需要在参数名称的开头加上冒号。
它应该是:
array(':id'=>$id,':dob_city'=>....