1

In Mongo DB you can do the following :

$m = new Mongo();
// select a database
$db=$m->databaseName;    // this creates/returns the db "databaseName"

How can I make a function such that dataBasename is passed as a dynamic variable? The below function currently fails.

load_db("databaseName");    

function load_db($dbname)
{
$m = new Mongo();
$db=$m->$dbname;   // I have also tried {$dbname}, with no success.

return $db;
}
0

1 Answer 1

5

You can use $db = $m->selectDb( $variable );: http://php.net/manual/en/mongo.selectdb.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.