php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13986 Cannot rollback transaction when die in class
Submitted: 2001-11-08 01:42 UTC Modified: 2001-12-13 06:28 UTC
From: leo_ngsungchun at sinaman dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.0.6 OS: Win2k / Linux + Oracle8i+Apache
Private report: No CVE-ID: None
 [2001-11-08 01:42 UTC] leo_ngsungchun at sinaman dot com
I am using a database class to manipulate data. 
I found that when the problem is terminated in 
the class, the transaction will be committed, 
even I've set the mode to OCI_DEFAULT.
The same case occured in both Win2k and Linux with 
Oracle and Apache.

////////////////////////////////////////////////
//  Schema
////////////////////////////////////////////////
/*
create table test (
  id   varchar2(5) not null,
  name varchar2(10),
  primary key (id)
);

////////////////////////////////////////////////
//  Source Code
///////////////////////////////////////////////
class Database {
	var $conn, $stmt, $row_data;

	function Database()
	{
		$DB_SERVER   = "";
		$DATABASE    = "";
		$DB_USER     = "test";
		$DB_PASSWORD = "test";

		putenv($DATABASE);
		$this->conn = OCILogon($DB_USER, $DB_PASSWORD, $DB_SERVER);

		if ($this->conn == false) {
			die("Cannot connect to server");
		}
	}

	function Query($sql)
	{
		$this->stmt = OCIParse($this->conn, $sql);
				
		if ($this->stmt == false) {
			die("Statement Error");
		}

		if (OCIExecute($this->stmt, OCI_DEFAULT) == false) {
			die("Cannot Execute Statment");
		}
	}

	function Commit()
	{
		OCICommit($this->conn);
	}

	function terminate()
	{
		die(" Not OK :( ");
	}
}	

$db = new Database();
$sql = "insert into test (id, name) values ('1', '1')";
$db->Query($sql);

$db->terminate(); // This will commit the transaction, 
                  // even the program is terminated.

die(" OK :) ");   // If the program is terminated here,
                  // the transaction is rollbacked.
$db->Commit();

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-08 01:47 UTC] leo_ngsungchun at sinaman dot com
I am using a database class to manipulate data. 
I found that when the program is terminated in 
the class, the transaction will be committed, 
even I've set the mode to OCI_DEFAULT.
The same case occured in both Win2k and Linux with 
Oracle and Apache.

////////////////////////////////////////////////
//  Schema
////////////////////////////////////////////////
/*
create table test (
  id   varchar2(5) not null,
  name varchar2(10),
  primary key (id)
);

////////////////////////////////////////////////
//  Source Code
///////////////////////////////////////////////
class Database {
	var $conn, $stmt, $row_data;

	function Database()
	{
		$DB_SERVER   = "";
		$DATABASE    = "";
		$DB_USER     = "test";
		$DB_PASSWORD = "test";

		putenv($DATABASE);
		$this->conn = OCILogon($DB_USER, $DB_PASSWORD, $DB_SERVER);

		if ($this->conn == false) {
			die("Cannot connect to server");
		}
	}

	function Query($sql)
	{
		$this->stmt = OCIParse($this->conn, $sql);
				
		if ($this->stmt == false) {
			die("Statement Error");
		}

		if (OCIExecute($this->stmt, OCI_DEFAULT) == false) {
			die("Cannot Execute Statment");
		}
	}

	function Commit()
	{
		OCICommit($this->conn);
	}

	function terminate()
	{
		die(" Not OK :( ");
	}
}	

$db = new Database();
$sql = "insert into test (id, name) values ('1', '1')";
$db->Query($sql);

$db->terminate(); // This will commit the transaction, 
                  // even the program is terminated.

die(" OK :) ");   // If the program is terminated here,
                  // the transaction is rollbacked.
$db->Commit();
 [2001-11-09 09:41 UTC] sniper@php.net
Have you tried PHP 4.0.6 ?

 [2001-11-13 21:56 UTC] leo_ngsungchun at sinaman dot com
I have just tried PHP 4.0.6. It has the same problem.
 [2001-11-17 13:53 UTC] mfischer@php.net
Do you see the same behavior when not using an object? I.e. moving all the stuff directly in the global namespace for testing purposes (or just use function instead of an object) ?


 [2001-12-13 06:28 UTC] sander@php.net
No feedback. Closing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 22:01:28 2024 UTC