PHP 사이트가 Interbase DB에 연결되어 있습니다. DB에는 사용자가로드 할 수있는 주문이 들어 있으며 화면에 표시됩니다. 사용자는 주문을 변경하여 저장할 수 있습니다. 이것은 작동하지만 2 명의 사용자가 동일한 레코드를로드하고 저장하면 순서는 마지막으로 저장 한 사용자가 변경 한 내용을 포함합니다.PHP로 Interbase 트랜잭션을 어떻게 사용합니까?
두 번째 사용자가 저장하려고 할 때 주문이 변경되었다는 메시지가 뜨고 주문이 저장되지 않도록하고 싶습니다.
나는 트랜잭션과 위의 시나리오를 구현하는 데스크톱 응용 프로그램을 가지고 있기 때문에 interbase에 트랜잭션이 있음을 알고 있습니다. 그러나 웹 환경에서 PHP를 사용하여 동일한 작업을 수행하는 방법을 알지 못합니다.
데스크톱 응용 프로그램은 항상 db를 열어두고 트랜잭션은 커밋 될 때까지 읽은 상태로 유지됩니다. PHP를 사용하면 각 쿼리가 실행될 때만 db와 트랜잭션을 열고 만들 수 있습니다. 내가 읽은 것에서 커밋되지 않은 경우 스크립트의 끝에서 트랜잭션이 롤백됩니다.
코드 순서를로드
PHP 코드 :
public function GetOrderDetails($in_OrderID)
{
$qry = "SELECT ID, ... , FROM CUSTOMER_INVOICE WHERE ID = $in_OrderID";
$this->dbconn = ibase_connect ($this->host, $this->username, $this->password);
$this->dbtrans = ibase_trans(IBASE_DEFAULT,$this->dbconn);
$result = ibase_query ($this->dbtrans, $qry);
while($row = ibase_fetch_row($qryResult))
{
}
ibase_free_result($in_FreeQry);
ibase_close($this->dbconn);
}
코드 저장하기 위해
PHP 코드 : 사람이 말해 줄 수 있다면 내가 잘못거야 어디
public function SaveOrderDetails()
{
$DoCommit = false;
try
{
$this->dbconn = ibase_connect ($this->host, $this->username, $this->password);
$this->dbtrans = ibase_trans(IBASE_DEFAULT,$this->dbconn);
// Insert/Update the order
if($this->UpdateOrder())
{
// Insert Order Items
if($this->InsertOrderItems())
{
$DoCommit = true;
}
else
{
$this->ErrorMsg = "ERROR 0003: Order Items could not be inserted";
}
}
else
{
$this->ErrorMsg = "ERROR 0002: Order could not be inserted/updated";
}
if($DoCommit)
{
if(ibase_commit($this->dbtrans))
{
$OrderResult = true;
}
else
{
ibase_rollback($this->dbtrans);
$this->ErrorMsg = "ERROR 0004: DB Qry Commit Error";
print $this->ErrorMsg ;
}
}
else
{
ibase_rollback($this->dbtrans);
}
}
catch(Exception $e)
{
ibase_rollback($this->dbtrans);
$this->ErrorMsg = "ERROR 0001: DB Exception: " . $e;
}
ibase_close($this->dbconn);
}
그게 좋을거야. 또는 아무도 Interbase를 사용하지 않으면 MySQL로 어떻게 할 것입니까? 난 테이블 잠금, 타임 스탬프 경로를 내려 가고 싶지 않아.
감사 레이