PhpRiot
Follow phpriot on Twitter
Sponsored Link
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store
Free iPad/iPhone App
Available on the App Store

  • PHP manual
  • Zend Framework manual
  • Smarty manual
  • PHP articles
  • PHP training

MongoDB::__construct

(PECL mongo >=0.9.0)

MongoDB::__constructCreates a new database

Description

MongoDB::__construct ( Mongo $conn , string $name )

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

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

<?php

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

?>

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

<?php

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

// or, if the name contains weird characters:

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

?>

Parameters

Mongo conn

Database connection.

name

Database name.

Return Values

Returns the database.

Errors/Exceptions

Throws default exception if the database name is invalid.

PHP Manual