php client - mongo db user group pune

13
:{PHP client} @n1shant

Upload: nishant-shrivastava

Post on 11-Nov-2014

1.398 views

Category:

Technology


3 download

Tags:

DESCRIPTION

A talk on PHP drivers and the official PHP-PECL library. Contains a walk through the library and how to use it.

TRANSCRIPT

Page 1: PHP client - Mongo db User Group Pune

:{PHP client}

@n1shant

Page 2: PHP client - Mongo db User Group Pune

{title : me}

● A Weboniser and a PHP nerd● MongoDb user● DevOps● Love working on Php, and a CakeBaker

Page 3: PHP client - Mongo db User Group Pune

{title : Content}

● PECL : MongoDb client● Playing with MongoDb-PHP Client● Using MongoDB-PHP Client

Page 4: PHP client - Mongo db User Group Pune

{title : mongoDb-PHP Client}

● Official Library● Easy and effective to use● Sweet-Simple-Easy

Page 5: PHP client - Mongo db User Group Pune

{title : core classes}

The Mongo ClientThe MongoDB Class

The Mongo Collection ClassThe Mongo Cursor Class

Page 6: PHP client - Mongo db User Group Pune

{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" ); ?>

Page 7: PHP client - Mongo db User Group Pune

{title : select database}<?php

$connection = new MongoClient();$db = $connection->dbname;

?>

: Be careful for the Database you provide..!

Page 8: PHP client - Mongo db User Group Pune

{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;

?>

Page 9: PHP client - Mongo db User Group Pune

{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 );

?>

Page 10: PHP client - Mongo db User Group Pune

{title : finding document}<?php

$connection = new MongoClient();$collection = $connection->meetup->MUGPune;

$document = $collection->findOne();var_dump( $document );

?>

Page 11: PHP client - Mongo db User Group Pune

{title : using cursor}<?php

$connection = new MongoClient();$collection = $connection->database->collectionName;

$cursor = $collection->find();foreach ( $cursor as $id => $value ) { echo "$id: "; var_dump( $value );}

?>

Page 12: PHP client - Mongo db User Group Pune

{title : demo app}

Created a simple task list manager

- http://checklistappmongo-nishant.rhcloud.com/login.php

Page 13: PHP client - Mongo db User Group Pune

Thanks

Would Love to help & answer your queries...

Nishant Shrivastava@n1shant

nishant-shrivastava