私はこのようなことをすることについて話している:
LOCKTABLEページの書き込み;
SELECT*FROMページWHEREcol='value';
INSERT INTO page(col1、col2)VALUES('val1'、val2);
テーブルのロックを解除します。
私はこのようなことをすることについて話している:
LOCKTABLEページの書き込み;
SELECT*FROMページWHEREcol='value';
INSERT INTO page(col1、col2)VALUES('val1'、val2);
テーブルのロックを解除します。
テーブルをロックするための実際のZendDBメソッドは表示されませんが、次のようにするだけです。
//Lock Table
$sql = "LOCK TABLE page WRITE";
$db->fetchRow($sql);
//Get your data
$sql = "SELECT * FROM page WHERE col='value'";
$result = $db->fetchAll($sql);
//Make the insert
$data = array( 'col1' => 'val1', 'col2' => 'val2' );
$db->insert('page', $data);
//Unlock tables
$sql = "UNLOCK TABLES";
$db->fetchRow($sql);
おそらく最善の解決策ではなく、テストされていません。しかし、それはあなたのために働くかもしれません。
更新:私はあなたのためのより良い解決策に出くわしました。トランザクションを使用する:
// Start a transaction explicitly.
$db->beginTransaction();
try {
//Get your data
$sql = "SELECT * FROM page WHERE col='value'";
$result = $db->fetchAll($sql);
//Make the insert
$data = array( 'col1' => 'val1', 'col2' => 'val2' );
$db->insert('page', $data);
// If all succeed, commit the transaction and all changes
// are committed at once.
$db->commit();
} catch (Exception $e) {
// If any of the queries failed and threw an exception,
// we want to roll back the whole transaction, reversing
// changes made in the transaction, even those that succeeded.
// Thus all changes are committed together, or none are.
$db->rollBack();
echo $e->getMessage();
}
私は最近同じ問題に遭遇し、トランザクションはうまく機能しました。間違いなく行く方法。
Zend_Dbトランザクションは、ロックを保証するものではありません。適切な分離トランザクションを作成する方法については、こちらをご覧ください。
$ this-> _ db-> getConnection()-> exec('LOCK TABLES page');
アダプターを使用する必要があると思いますが、ロックが機能するかどうかはわかりません。
$ model-> getAdapter()-> query($ sql、$ bind);