English | 简体中文 | 繁體中文
查询

MongoDB\Driver\ServerDescription::getHelloResponse()函数—用法及示例

「 获取服务器的Hello响应 」


函数名称:MongoDB\Driver\ServerDescription::getHelloResponse()

函数描述:该函数用于获取服务器的Hello响应。

适用版本:MongoDB PHP驱动版本1.2.0及以上

用法:

public function MongoDB\Driver\ServerDescription::getHelloResponse(): ?array

参数: 该函数没有参数。

返回值:

  • 如果服务器的Hello响应成功,则返回一个关联数组,包含服务器的详细信息。
  • 如果服务器的Hello响应失败,则返回null。

示例:

<?php
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");

$server = new MongoDB\Driver\ServerDescription("localhost:27017");

$response = $server->getHelloResponse();

if ($response) {
    echo "服务器的Hello响应成功:\n";
    print_r($response);
} else {
    echo "服务器的Hello响应失败\n";
}
?>

注意:在使用这个函数之前,你需要先创建一个MongoDB\Driver\Manager对象,并将服务器的地址传递给MongoDB\Driver\ServerDescription对象的构造函数。

补充纠错
热门PHP函数
分享链接