文档菜单
文档首页
/ / /
PHP 库手册
/ /

MongoDB\Client::startSession()

本页内容

  • 定义
  • 参数
  • 返回值
  • 错误/异常
  • 示例
  • 另请参阅

新增自版本1.3.

MongoDB\Client::startSession()

为使用此客户端启动新的客户端会话。

function startSession(array $options = []): MongoDB\Driver\Session
$options : array
一个数组,指定所需的选项。请参阅MongoDB\Driver\Manager::startSession() 扩展的文档中列出了支持的选项。

一个 MongoDB\Driver\Session 对象。

MongoDB\Driver\Exception\InvalidArgumentException 与扩展级别参数或选项解析相关的错误。

MongoDB\Driver\Exception\RuntimeException 用于扩展级别其他错误(例如连接错误)。

以下示例启动了一个新的会话

<?php
$client = new MongoDB\Client;
$session = $client->startSession();
var_dump($session);

输出结果将类似于

object(MongoDB\Driver\Session)#2043 (4) {
["logicalSessionId"]=>
array(1) {
["id"]=>
object(MongoDB\BSON\Binary)#225 (2) {
["data"]=>
string(16) "................"
["type"]=>
int(4)
}
}
["clusterTime"]=>
NULL
["causalConsistency"]=>
bool(true)
["operationTime"]=>
NULL
}

返回

selectDatabase()