:{PHP client}
@n1shant
{title : me}
● A Weboniser and a PHP nerd● MongoDb user● DevOps● Love working on Php, and a CakeBaker
{title : Content}
● PECL : MongoDb client● Playing with MongoDb-PHP Client● Using MongoDB-PHP Client
{title : mongoDb-PHP Client}
● Official Library● Easy and effective to use● Sweet-Simple-Easy
{title : core classes}
The Mongo ClientThe MongoDB Class
The Mongo Collection ClassThe Mongo Cursor Class
{title : connection}
<?php// connects to localhost:27017
$connection = new MongoClient(); // connect to a remote host (default port: 27017)
$connection = new MongoClient( "mongodb://example.com" ); // connect to a remote host at a given port
$connection = new MongoClient( "mongodb://example.com:65432" ); ?>
{title : select database}<?php
$connection = new MongoClient();$db = $connection->dbname;
?>
: Be careful for the Database you provide..!
{title : Collection}<?php
$connection = new MongoClient();$db = $connection->meetup;
// select a collection:$collection = $db->mongodb;// or, directly selecting a database and collection:$collection = $connection->meetup->mongodb;
?>
{title : Inserting a document}<?php
$meetUpDocument = array( "name" => "MongoDb User Meet Up", "slug" => "MUGPune",
"info" => (object)array( "at" => “Webonise Lab”), "versions" => array("0.1", "0.2")
);$connection = new MongoClient();$mugCollection = $connection->meetup->MUGPune;$mugCollection->insert( $meetUpDocument );
?>
{title : finding document}<?php
$connection = new MongoClient();$collection = $connection->meetup->MUGPune;
$document = $collection->findOne();var_dump( $document );
?>
{title : using cursor}<?php
$connection = new MongoClient();$collection = $connection->database->collectionName;
$cursor = $collection->find();foreach ( $cursor as $id => $value ) { echo "$id: "; var_dump( $value );}
?>
{title : demo app}
Created a simple task list manager
- http://checklistappmongo-nishant.rhcloud.com/login.php
Thanks
Would Love to help & answer your queries...
Nishant Shrivastava@n1shant
nishant-shrivastava