Oracle与PHP中多表回滚

3

我正在尝试插入一个带有一些字段的表格

$ecode = 1000; 
$location = 'B'; 
$file_id = 1; 
$accessed_on = '30-NOV-14';

我的代码是

$conn = oci_connect('username', 'passwd', '//server/db');    
if (!$conn) {    
    $e = oci_error();    
    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);    
} else {     
}    

$query_Test = "
    insert into example(ECODE,LOCATION,FILE_ID,ACCESSED_ON) 
    values($ecode,'$location',$file_id,'$accessed_on')";   

$parse_Test = oci_parse($conn, $query_Test);    
if(oci_execute($parse_Test)) {
    echo 'Success';        
    $query_Test1 = "
        update example     
        set ACCESSED_ON=03-nov-14,    
        where LOCATION='B'";    

    $parse_Test1 = oci_parse($conn, $query_Test1);    

    if(oci_execute($parse_Test1)){      
        oci_rollback($conn);    
    }    
}

但是当query_Test1失败时,它不会回滚query_Test。该怎么办?请有人帮忙,谢谢!

http://php.net/manual/zh/function.oci-execute.php <- 这些文档非常重要。一定要查看。 - Mat
http://php.net/manual/zh/function.oci-rollback.php,这可能也会有所帮助。 - Exhausted
1个回答

0
当你编写 oci_execute($test,OCI_DEFUALT); 时,它会起作用。
因为如果你没有定义任何第二个参数,它默认是自动提交。通过定义此参数,它不会自动提交(oci_defualt)或(OCI_NO_AUTO_COMMIT)。
而且,它为什么没有回滚呢?因为如果你提交了(保存)状态,你就不能回滚。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接