0

阅读前:我知道表格太奇怪太长了,需要标准化;但由于某种原因,这是我的数据库,我应该使用这张表!对于那个很抱歉!简而言之:我收到以下异常:

带有消息“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\">&times;</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\">&times;</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\">&times;</button>
                      </div>"; */
                }
                return $Msg;
}

当我替换我的插入方法的值时(在 UpdateTableHrForms 中,用错误给我的值并在 mysql 中运行它;没有错误;但在 PHP 中它给了我错误;如果我在做,你能帮帮我吗?有事吗?)

4

1 回答 1

2

您传递给的数组的execute格式不正确;您需要在参数名称的开头有冒号。

它应该是:

array(':id'=>$id,':dob_city'=>....
于 2013-09-12T20:14:00.580 回答