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

search for in the

MongoDB::createCollection> <MongoDB::command
[edit] Last updated: Fri, 17 May 2013

view this page in

MongoDB::__construct

(PECL mongo >=0.9.0)

MongoDB::__constructCreates a new database

Description

public MongoDB::__construct ( MongoClient $conn , string $name )

This method is not meant to be called directly. The preferred way to create an instance of MongoDB is through MongoClient::__get() or MongoClient::selectDB().

If you're ignoring the previous paragraph and want to call it directly you can do so:

<?php

$m 
= new MongoClient();
$db = new MongoDB($m'mydbname');

?>

But don't. Isn't this much nicer:

<?php

$m 
= new MongoClient();
$db $m->mydbname;

// or, if the name contains weird characters:

$db $m->selectDB('my,db:name');

?>

Parameters

MongoClient conn

Database connection.

name

Database name.

Return Values

Returns the database.

Errors/Exceptions

Throws default exception if the database name is invalid.



add a note add a note User Contributed Notes MongoDB::__construct - [0 notes]
There are no user contributed notes for this page.

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