Interbase DB に接続された PHP サイトがあります。DB には、ユーザーがロードして画面に表示できる注文が含まれています。ユーザーは注文を変更して保存できます。これは機能しますが、2 人のユーザーが同じレコードを読み込んで保存すると、最後に保存したユーザーが行った変更が注文に含まれます。
2 番目のユーザーが保存しようとすると、注文が変更されたことを示すメッセージがポップアップ表示され、注文の保存が停止されます。
トランザクションと上記のシナリオを実装するデスクトップ アプリがあるので、interbase にはこれを行うためのトランザクションがあることを知っています。しかし、Web環境でPHPで同じことを行う方法がわかりません。
デスクトップアプリはデータベースを常に開いたままにし、トランザクションは読み取られてからコミットされるまで存続します。PHP では、データベースとトランザクションは、各クエリが実行されたときにのみ開かれ、作成されます。私が読んだことから、コミットされていない場合、トランザクションはスクリプトの最後にロールバックされます。
注文をロードするコード
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 をどのように使用しますか? テーブルロック、タイムスタンプルートをたどりたくありません。
ありがとうレイ