Core Classes
PHP Manual

The Mongo class

Introduction

A connection between PHP and MongoDB.

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

<?php

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

?>

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

Class synopsis

Mongo {
/* Constants */
const string VERSION ;
const string DEFAULT_HOST = "localhost" ;
const int DEFAULT_PORT = 27017 ;
/* Fields */
public boolean $Mongo->connected = FALSE ;
public string $status = NULL ;
protected string $server = NULL ;
protected boolean $persistent = NULL ;
/* Methods */
public bool Mongo::close ( void )
public bool Mongo::connect ( void )
protected bool Mongo::connectUtil ( void )
Mongo::__construct ([ string $server = "mongodb://localhost:27017" [, array $options = array("connect" => TRUE) ]] )
public array Mongo::dropDB ( mixed $db )
public MongoDB Mongo::__get ( string $dbname )
public array Mongo::getHosts ( void )
public static int Mongo::getPoolSize ( void )
public string Mongo::getSlave ( void )
public bool Mongo::getSlaveOkay ( void )
public array Mongo::listDBs ( void )
public array Mongo::poolDebug ( void )
public MongoCollection Mongo::selectCollection ( string $db , string $collection )
public MongoDB Mongo::selectDB ( string $name )
public static bool Mongo::setPoolSize ( int $size )
public bool Mongo::setSlaveOkay ([ bool $ok = true ] )
public string Mongo::switchSlave ( void )
public string Mongo::__toString ( void )
}

Predefined Constants

Mongo Constants

Mongo::VERSION
PHP driver version. May be suffixed with "+" or "-" if it is in-between versions.
Mongo::DEFAULT_HOST
"localhost"
Host to connect to if no host is given.
Mongo::DEFAULT_PORT
27017
Port to connect to if no port is given.

Fields

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.

See Also

MongoDB core docs on » connecting.

Table of Contents


Core Classes
PHP Manual