downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Mongo::close> <Core Classes
[edit] Last updated: Sat, 07 Jan 2012

view this page in

The Mongo class

(No version information available, might only be in SVN)

Einführung

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.

Klassenbeschreibung

Mongo {
/* Konstanten */
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 ;
/* Methoden */
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 )
}

Vordefinierte Konstanten

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.

Siehe auch

MongoDB core docs on » connecting.

Inhaltsverzeichnis



add a note add a note User Contributed Notes Mongo
Fausto Vanin @faustovanin 09-Feb-2011 12:31
For those who are concerned on parsing JSON associative arrays from queries, this class could be useful. You just have to extend it and call parent constructor and it gets the job done.
It automatically initializes all your object attributes getting values from the array.

<?php

   
#doc
    #    classname:    MongoClass
    #    scope:        PUBLIC
    #
    #/doc
   
   
class MongoClass
   
{
       
#    internal variables
       
protected $id;
       
       
#    Constructor
       
function __construct ($attList = array())
        {
           
$reflection = new ReflectionObject($this);

            foreach (
$attList as $attName => $attValue)
            {
               
$attObj = $reflection->getProperty($attName);
               
$attObj->setAccessible(true);
               
$attObj->setValue($this, $attValue);
            }
        }
       
###   
   
   
}
   
###
       
class A extends MongoClass {
                private
$name;
                private
$value;
                private
$weight;

                public function
__construct($attList) {
                       
parent::__construct($attList);
                }
        }

       
$attList = array(
               
"name" => "Beer",
               
"value" => "Delicious",
               
"weight" => 15.2
       
); //This is your JSON object associative aray

       
$a = new A($attList);

?>
markh789 at gmail dot com 07-Jan-2011 10:32
Here is a simple connection function :)

<?php
function MongoConnect($username, $password, $database, $host) {
   
$con = new Mongo("mongodb://{$username}:{$password}@{$host}"); // Connect to Mongo Server
   
$db = $con->selectDB($database); // Connect to Database
}
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites