我正在运行以下代码:
$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("Y-m-d 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()))
这应该可以指示出了什么问题以及为什么事情没有按预期执行。