$mongodb = new Mongo ();
$connection = new Mongo ("$dburl: $port"); Connect to a remote host (default port)
$mydb = $mongodb->mydb; Creating a database implicitly MyDB
$mydb = $mongodb->selectdb ("MyDB"); Directly select a database that already exists
$collection = $mydb->mycollect; Select the anthology you use, and if it does not, automatically create
$collection = $db->selectcollection (' mydb '); Select only, do not create
Insert a new record
$collection->insert ("name" = "L4yn3", "age" = "ten", "Sex": "Unknow");
Modify a record
$where = Array ("name" = "L4yn3");
$update _item = Array (' $set ' =>array ("age" = "+", "Sex": "secret"));
$collection->update ($where, $update _item);
$options [' multiple '] = true; The default is false, whether to change the matching multiline
$collection->update ($where, $update _item, $options);
Query records
$myinfo = $collection->findone (Array ("name" = "L4yn3"));
$myinfo = $collection->findone (Array ("name" =
"L4yn3"), Array ("Age" = "15"));
Find by criteria:
$query = Array ("name" = "L4yn3");
$cursor = $collection->find ($query); Find documents that meet $query in the $collectio collection
while ($cursor->hasnext ())
{
Var_dump ($cursor->getnext ()); Returns the array
}
Returns the number of document records
$collection->count ();
To delete a database:
$connection->dropdb ("...");
List all available databases:
$m->listdbs (); No return value
To close the connection:
$connection->close ();
PHP various connection to MONGODB database parameter mode
Connection localhost:27017
$conn = new Mongo ();
Connecting the remote host default port
$conn = new Mongo (' test.com ');
Connecting remote host 22011 ports
$conn = new Mongo (' test.com:22011 ');
MongoDB has user name password
$conn = new Mongo ("Mongodb://${username}:${password} @localhost")
MongoDB has a user name password and specifies a database blog
$conn = new Mongo ("Mongodb://${username}:${password} @localhost/blog");
Multiple servers
$conn = new Mongo ("mongodb://localhost:27017,localhost:27018");
http://www.bkjia.com/PHPjc/825286.html www.bkjia.com true http://www.bkjia.com/PHPjc/825286.html techarticle $mongodb = new Mongo ();//$connection = new Mongo ("$dburl: $port");//Connect to a remote host (default port) $mydb = $mongodb-mydb; Implicit creation of database mydb $mydb = $mongodb-...