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

MongoDB\Client::__get()

本页内容

  • 定义
  • 参数
  • 返回值
  • 行为
  • 示例
  • 相关内容
MongoDB\Client::__get()

在服务器上选择一个数据库。这是魔术方法的别名,对应于selectDatabase() 方法。

function __get(string $databaseName): MongoDB\Database
$databaseName : string
要选择的数据库名称。

一个 MongoDB\Database 对象。

所选数据库继承自 Client 对象的选项,如读取偏好和类型映射。如果您想覆盖任何选项,请使用 MongoDB\Client::selectDatabase() 方法。

注意

要选择名称包含特殊字符(如 -)的数据库,请使用复杂语法,例如 $client->{'that-database'}

或者,MongoDB\Client::selectDatabase() 支持选择名称包含特殊字符的数据库。

以下示例选择了 testanother-app 数据库

<?php
$client = new MongoDB\Client;
$test = $client->test;
$anotherApp = $client->{'another-app'};

返回

__construct()