簡體   English   中英

PDO插入SQL不會錯誤執行

[英]PDO Insert SQL not executing with no errors

我正在運行此代碼:

$stmt = $pdo_conn->prepare("INSERT into ticket_updates (ticketnumber, notes, datetime, contact_name, contact_email, customer, internal_message, type) values (:ticketnumber, :notes, :datetime, :contact_name, :contact_email, :customer, :internal_message, :type) ");
            $stmt->execute(array(':ticketnumber' => $ticketnumber, 
            ':notes' => $TicketSummary, 
            ':datetime' => date("Y-m-d H:i:s"),  
            ':contact_name' => $Ticket_ContactName, 
            ':contact_email' => $Ticket_ContactEmail, 
            ':customer' => 'Y', 
            ':internal_message' => 'N', 
            ':type' => 'update'));

所有表列都存在並且正確,但是沒有超過這一點

我嘗試了var_dump($stmt); 但一無所獲

使用以下命令驗證連接是否正確建立

try
{
    $dbh = new PDO("mysql:host=xxxxxxxxxxxx;dbname=streaming", "xxxx", "xxxx");
}
catch (Exception $e)
{
    throw new Exception( 'Something really gone wrong', 0, $e);
}

您也可以像這樣執行時輸出錯誤

$sth->execute() or die(print_r($sth->errorInfo(), true));

最后,您可能還需要在頁面上啟用錯誤,因此請將其放置在頁面標題或單個頁面的最頂端:

error_reporting(-1);

負1表示它將打印所有錯誤。

在發現錯誤之前,很難進一步診斷問題,但是問題可能歸結為與數據庫的連接或如何形成參數數組。

將錯誤報告添加到您的pdo:

$pdo_conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);

在執行插入命令之前。

然后在插入命令上,輸出錯誤

$stmt->execute(array(':ticketnumber' => $ticketnumber, ':notes' => $TicketSummary, ':datetime' => date("Ymd H:i:s"),
':contact_name' => $Ticket_ContactName, ':contact_email' => $Ticket_ContactEmail, ':customer' => 'Y', ':internal_message' => 'N', ':type' => 'update')) or die("ERROR: " . implode(":", $pdo_conn->errorInfo()))

這應該告訴您什么地方出了問題以及為什么事情沒有按預期執行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM