PDF(美国Ltr)- 2.4 mb
PDF (A4)- 2.4 mb
CollectionFind:绑定
将值绑定到查询占位符
描述
公共mysql_xdevapi \ CollectionFindmysql_xdevapi \ CollectionFind::绑定(数组placeholder_values);
它允许用户将参数绑定到find操作的搜索条件中的占位符。占位符的形式为:NAME,其中':'是一个通用前缀,必须始终存在于任何NAME之前,NAME是占位符的实际名称。如果必须在搜索条件中替换多个实体,则bind函数接受占位符列表。
参数
-
placeholder_values
-
搜索条件中要替换的值;允许多个值,并作为数组传递,其中“PLACEHOLDER_NAME => PLACEHOLDER_VALUE”。
返回值
CollectionFind对象,或使用execute()链返回Result对象。
例子
例5.29mysql_xdevapi \ CollectionFind::绑定
例子
<?php $session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");$session->sql("DROP DATABASE IF EXISTS ")->execute();$session->sql("CREATE DATABASE addressbook")->execute();$session = $session- getSchema("addressbook");$create = $schema->createCollection("people");结果=创建- >添加美元('{“名称”:“阿尔弗雷德”,“年龄”:18,“工作”:“管家”}”)- >执行();/ /……$collection = $schema->getCollection("people");$result = $collection ->find('job like:job and age >:age') ->bind(['job' => 'Butler', 'age' => 16]) ->execute(); var_dump($result->fetchAll()); ?>
上面的例子将输出类似于:
Array (1) {[0]=> Array (4) {["_id"]=> string(28)"00005b6b536100000000000000cf" ["age"]=> int(18) ["job"]=> string(6)"Butler" ["name"]=> string(6)“阿尔弗雷德”}}