简体   繁体   English

PHP PDO-ROLLBACK TRANSACTION请求没有相应的BEGIN TRANSACTION

[英]PHP PDO - The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION

While inserting into MSSQL using PHP PDO Dblib I am having this error 使用PHP PDO Dblib插入MSSQL时出现此错误

exit signal Segmentation fault in apache error log apache错误日志中的退出信号分段错误

When I checked the free tds log the error is 当我检查免费的tds日志时,错误是

The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION ROLLBACK TRANSACTION请求没有相应的BEGIN TRANSACTION

However this is happening for a particular case only that is when I have string for a float data type. 但是,这仅在特定情况下才发生,即当我具有用于float数据类型的字符串时。 Below is my code: 下面是我的代码:

$conn = new PDO('dblib:host=hostname;dbname=mydbname', 'user', 'password');
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$conn->beginTransaction();
$query = 'INSERT INTO [TestTable] ([RecordNo], [Paymode], [VATVALUE])
          VALUES (:RecordNo, :Paymode, :VATVALUE)';
$stmt = $conn->prepare($query);
try {
    $stmt->execute( [":VATVALUE" => "158.4'", ":Paymode" => "CREDIT", 
                                    ":RecordNo" => "ABC-312735"] );
    $conn->commit();
} catch(PDOException $e) {
    $conn->rollback();
}

Please note the vat value which I have set it as 请注意我已将其设置为

158.4' 158.4'

for replicating the error. 复制错误。 However when I remove the transaction statements then it is throwing the proper error ie 但是,当我删除事务语句时,它将抛出适当的错误,即

Error converting data type varchar to float 将数据类型varchar转换为float时出错

Interestingly the beginTransaction() is working perfectly if I specify a wrong column name in the statement. 有趣的是,如果我在语句中指定了错误的列名,beginTransaction()会完美地工作。 The transaction is not working only for this conversion error and throwing signal segmentation fault error. 事务不只针对此转换错误和抛出信号分段错误错误起作用。

I am using PHP 7.0 in ubuntu 16.04. 我在Ubuntu 16.04中使用PHP 7.0。 Wondering why rollback working fine in all cases like wrong column names or table name but not in the conversion case. 想知道为什么回滚在所有情况下都能正常工作,例如错误的列名或表名,但在转换情况下却不行

There are errors in SQL Server which will automatically roll back your transaction, and it's an error to attempt a rollback after that. SQL Server中有错误会自动回滚您的事务,而在此之后尝试回滚是错误的。 Instead of 代替

$conn->rollback();

try executing the batch 尝试执行批处理

if @@trancount>0 rollback;

I don't know PHP but perhaps something like: 我不知道PHP,但也许像这样:

$conn->prepare("if @@trancount>0 rollback;")->execute();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 回滚事务请求没有相应的开始事务 - The Rollback transaction request has no corresponding begin transaction 获取错误“回滚事务请求没有相应的开始事务” - Getting error “The rollback transaction request has no corresponding begin transaction” SQL Server:ROLLBACK TRANSACTION请求没有相应的BEGIN TRANSACTION - SQL Server: the ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION ROLLBACK TRANSACTION 请求没有对应的BEGIN TRANSACTION,但是还是报错 - The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION, but still getting an error COMMIT TRANSACTION 请求没有对应的 BEGIN TRANSACTION - The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION 运行UDATE语句时,ROLLBACK TRANSACTION请求没有对应的BEGIN TRANSACTION - The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION when ran UDATE statement ROLLBACK TRANSACTION请求在SQL Server错误8114之后没有对应的BEGIN TRANSACTION - ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION following SQL Server Error 8114 ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION - 在 while 循环内调用过程时 - ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION - when calling a procedure inside while loop TSQL错误:COMMIT TRANSACTION请求没有相应的BEGIN TRANSACTION - TSQL error: The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION 消息3902,级别16,状态1. COMMIT TRANSACTION请求没有相应的BEGIN TRANSACTION - Msg 3902, Level 16, State 1. The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM