(無版本資訊,可能僅存在於 Git 中)
CollectionFind::lockExclusive — 以獨佔鎖定執行操作
$lock_waiting_option
= ?): mysql_xdevapi\CollectionFind以獨佔方式鎖定文件。只要文件被鎖定,其他交易就無法更新文件、使用 SELECT ... LOCK IN SHARE MODE
或在某些交易隔離級別中讀取資料。一致性讀取會忽略讀取檢視中存在的記錄上設定的任何鎖定。
為了避免並行問題,將此函式與 mysql_xdevapi\Collection::modify() 方法一起使用是合理的。基本上,此函式使用列鎖定來序列化對列的存取。
lock_waiting_option
可選的等待選項。預設值為 MYSQLX_LOCK_DEFAULT
。有效值為以下常數:
回傳一個 CollectionFind 物件,可用於進一步處理。
範例 #1 mysql_xdevapi\CollectionFind::lockExclusive() 範例
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$schema = $session->getSchema("addressbook");
$collection = $schema->createCollection("people");
$session->startTransaction();
$result = $collection
->find("age > 50")
->lockExclusive()
->execute();
// ... 對物件進行操作
// 完成交易並解鎖文件
$session->commit();
?>