(沒有版本資訊,可能只在 Git 中)
CollectionModify::bind — 將值繫結至查詢佔位符
將參數繫結至修改操作搜尋條件中的佔位符。
佔位符的格式為 :NAME,其中 ':' 是一個通用前綴,必須始終存在於任何 NAME 之前,而 NAME 是佔位符的名稱。如果在修改操作的搜尋條件中需要替換多個實體,則 bind 方法接受一個佔位符列表。
placeholder_values
要在搜尋條件中替換的佔位符值。允許多個值,並且必須以 PLACEHOLDER_NAME->PLACEHOLDER_VALUE 的映射陣列形式傳遞。
一個 CollectionModify 物件,可用於執行命令或添加其他操作。
範例 #1 mysql_xdevapi\CollectionModify::bind() 範例
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$schema = $session->getSchema("addressbook");
$collection = $schema->createCollection("people");
$result = $collection
->add(
'{"name": "Bernie",
"traits": ["Friend", "Brother", "Human"]}')
->execute();
$collection
->modify("name = :name")
->bind(['name' => 'Bernie'])
->arrayAppend('traits', 'Happy')
->execute();
$result = $collection
->find()
->execute();
print_r($result->fetchAll());
?>
上述範例將輸出類似以下的內容
Array ( [0] => Array ( [_id] => 00005b6b53610000000000000110 [name] => Bernie [traits] => Array ( [0] => Friend [1] => Brother [2] => Human [3] => Happy ) ) )