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> <Примери
[edit] Last updated: Fri, 18 Sep 2009

view this page in

The Mongo class

Увод

The connection point between MongoDB and PHP.

This class is used to initiate a connection and for database server commands. A typical use is:

<?php
$m 
= new Mongo(); // connect
$db $m->selectDatabase(); // get a database object
?>

Синтаксис за класове

Mongo
Mongo {
/* Methods */
public boolean close ( void )
public boolean connect ( void )
protected boolean connectUtil ( string $username , string $password )
__construct ([ string $server = NULL [, boolean $connect = TRUE [, boolean $persistent = FALSE [, boolean $paired = FALSE ]]]] )
public array dropDB ( mixed $db )
public bool forceError ( void )
public array lastError ( void )
public boolean pairConnect ( void )
public boolean pairPersistConnect ([ string $username = "" [, string $password = "" ]] )
public boolean persistConnect ([ string $username = "" [, string $password = "" ]] )
public array prevError ( void )
public array repairDB ( MongoDB $db [, boolean $preserve_cloned_files = false [, boolean $backup_original_files = false ]] )
public array resetError ( void )
public MongoCollection selectCollection ( string|MongoDB $db , string $collection )
public MongoDB selectDB ( string $dbname )
public string __toString ( void )
}

Съдържание



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