PDO参数号错误消息无效

时间:2014-01-08 13:04:18

标签: php mysql pdo

我正在运行此PDO SQL查询:

$stmt = $pdo_conn->prepare("INSERT into ticket_updates (ticket_seq, notes, datetime, updatedby, customer, internal_message) values (:ticket_seq, :notes, :datetime, :updatedby, :customer, :internal_message) ");
                $stmt->execute(array(':ticket_seq' => $ticketnumber, 
                ':notes' => addslashes($message), 
                ':datetime' => date("Y-m-d H:i:s"),  
                ':updateedby' => $last_updated_by, 
                ':customer' => 'Y', 
                ':internal_message' => 'no'));

但收到此错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in /home/integra/public_html/autocheck/support_emails.php:479 Stack trace: #0 /home/integra/public_html/autocheck/support_emails.php(479): PDOStatement->execute(Array) #1 {main} thrown in /home/integra/public_html/autocheck/support_emails.php on line 479

我不确定问题是什么,所有其他查询都可以正常工作

3 个答案:

答案 0 :(得分:5)

在准备中,您调用此参数updatedby,但在绑定中,您updateedby修复此问题,可能会解决您的错误。

答案 1 :(得分:0)

可能是拼写错误,因为错误消息显示:参数未定义。仔细检查您的参数。

答案 2 :(得分:0)

在这种情况下,您可能希望使用未命名的参数。这样可以省去你输入两次麻烦的麻烦,并提高可维护性,恕我直言。

$stmt = $pdo_conn->prepare(
    "INSERT into ticket_updates (".
        "ticket_seq, notes, datetime, updatedby, customer, internal_message)". 
        "values (?, ?, ?, ?, ?, ?)");

$stmt->execute(array(
            $ticketnumber, 
            addslashes($message), 
            date("Y-m-d H:i:s"),  
            $last_updated_by, 
            'Y', 
            'no'));
相关问题