我正在尝试向某些用户(在PHP中)显示由于某种原因某些SQL操作提交失败的用户。但它看起来像PHP DBO永远不会得到错误。这是对实际代码的简化。
$conn = new PDO("dblib:host=$host; dbname=$db", $user, $pass);
$sql = "
BEGIN TRAN
INSERT INTO table (field) VALUES (1)
INSERT INTO table (field) VALUES (2)
INSERT INTO table (field) VALUES ('this will throw an error')
COMMIT
IF @@ERROR <> 0 BEGIN
ROLLBACK
RAISERROR('Nops.', 16, 1)
END";
try {
$rs = $conn->query($sql);
} catch (PDOException $e) {
echo 'It never gets here';
}
如何判断此交易未被提交?