Clase de bază
PHP Manual

The MongoClient class

(PECL mongoclient >=1.3.0)

Introducere

A connection between PHP and MongoDB.

This class is used to create and manage connections. A typical use is:

Example #1 MongoClient basic usage

<?php

$m 
= new MongoClient(); // connect
$db $m->foo// get the database named "foo"

?>

See MongoClient::__construct() and the section on connecting for more information about creating connections.

Sinopsisul clasei

MongoClient {
/* Constante */
const string VERSION ;
const string DEFAULT_HOST = "localhost" ;
const int DEFAULT_PORT = 27017 ;
const string RP_PRIMARY = "primary" ;
const string RP_PRIMARY_PREFERRED = "primaryPreferred" ;
const string RP_SECONDARY = "secondary" ;
const string RP_SECONDARY_PREFERRED = "secondaryPreferred" ;
const string RP_NEAREST = "nearest" ;
/* Proprietăți */
public boolean $connected = FALSE ;
public string $status = NULL ;
protected string $server = NULL ;
protected boolean $persistent = NULL ;
/* Metode */
public __construct ([ string $server = "mongodb://localhost:27017" [, array $options = array("connect" => TRUE) ]] )
public bool close ([ boolean|string $connection ] )
public bool connect ( void )
public array dropDB ( mixed $db )
public MongoDB __get ( string $dbname )
public static void getConnections ( void )
public array getHosts ( void )
public array getReadPreference ( void )
public array listDBs ( void )
public MongoCollection selectCollection ( string $db , string $collection )
public MongoDB selectDB ( string $name )
public bool setReadPreference ( string $read_preference [, array $tags ] )
public string __toString ( void )
}

Constante predefinite

MongoClient Constants

MongoClient::VERSION
PHP driver version. May be suffixed with "+" or "-" if it is in-between versions.
MongoClient::DEFAULT_HOST
"localhost"
Host to connect to if no host is given.
MongoClient::DEFAULT_PORT
27017
Port to connect to if no port is given.
MongoClient::RP_PRIMARY
"primary"
Read preference for the primary replica set member.
MongoClient::RP_PRIMARY_PREFERRED
"primaryPreferred"
Read preference for preferring the primary replica set member.
MongoClient::RP_SECONDARY
"secondary"
Read preference for a secondary replica set member.
MongoClient::RP_SECONDARY_PREFERRED
"secondaryPreferred"
Read preference for preferring a secondary replica set member.
MongoClient::RP_NEAREST
"nearest"
Read preference for the nearest replica set member.

Fields

connected
This property will be set to TRUE if we have a open connection the database based on the ReadPreference and tagsets (for ReplicaSet connections), FALSE otherwise. This property does not take authentication into account.
status
If this is a persistent connection, if the connection was created for this object or is being reused. If this is not a persistent connection, this field should be NULL.

Vedeți de asemenea

Cuprins


Clase de bază
PHP Manual