2014-01-13 150 views
-1

我試圖運行此PDO預處理語句PDO預處理語句未捕獲的異常錯誤消息

$stmt = $pdo_conn->prepare(
    "INSERT into email_attachments (email_seq, attachment) 
    values (:email_seq, :attachment) "); 
$stmt->execute(array(
    ':email_seq' => $admin_email_sequence, 
    ':attachment' => $_SERVER["DOCUMENT_ROOT"].'/'.$settings["ticket_files_folder"].'/'.$ticketnumber.'-'.$currentDate.'-'.$at[filename], $at[attachment] 
)); 

,但我得到這個錯誤:

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

+2

什麼不明確錯誤消息? – PeeHaa

回答

1

你有一個額外你執行數組裏面,你也有一個額外的數組元素($在[附件]

試試這個代碼

$stmt = $pdo_conn->prepare("INSERT into email_attachments (email_seq, attachment) values (:email_seq, :attachment) "); 
$stmt->execute(array(
    ':email_seq' => $admin_email_sequence, 
    ':attachment' => $_SERVER["DOCUMENT_ROOT"] . '/' . $settings["ticket_files_folder"] . '/' . $ticketnumber . '-' . $currentDate . '-' . $at[filename] 
)); 
2

:attachment條目的結尾處,您有一個逗號,而不是我認爲應該是一段時間。

.$at[filename], $at[attachment] 
       ^-- here 

這會導致異常,因爲您的查詢中有2個標籤,數組中有3個標籤。

相關問題