2010/1/30 PHP Study Tokyo  #49 Yasushi Ichikawa (id:cakephper) ‏ (id:ichikaway) MongoDB + PHP + Cake
self-introduction Yasushi Ichikawa Twitter: @cakephper Twitter: @ichikaway  Blog English http://cake.eizoku.com/blog/ Japa...
TOPIC 1. MongoDB 2. PHP + MongoDB 3. CakePHP + MongoDB
MongoDB <ul><li>Open-source non-relational DB </li></ul><ul><ul><li>Scalable </li></ul></ul><ul><ul><li>Schema less </li><...
MongoDB <ul><li>Term </li></ul><ul><li>Table = Collection </li></ul><ul><li>Row = Document </li></ul>
MongoDB <ul><li>Not replace all RDB </li></ul><ul><li>Mongo not Fit </li></ul><ul><ul><li>Need join, Transaction </li></ul...
MongoDB <ul><li>Performance </li></ul><ul><ul><li>Business insider </li></ul></ul><ul><ul><ul><li>http://www.businessinsid...
MongoDB <ul><li>Schema less </li></ul><ul><ul><li>Document: bson (similar json) </li></ul></ul><ul><ul><ul><li>Binary data...
MongoDB <ul><li>RDB schema </li></ul><ul><ul><li>Natural data structure?? </li></ul></ul>Blog Title Text tag1,tag2,tag3 Co...
MongoDB <ul><li>Schema less </li></ul><ul><ul><li>Natural data structure </li></ul></ul>Blog collection Title : xxxx Text ...
MongoDB DEMO
Pecl Mongo MongoDB + PHP
Pecl Mongo <ul><li>Pecl Mongo </li></ul><ul><ul><li>pecl install mongo  </li></ul></ul><ul><ul><li>php.ini extension=mongo...
Pecl Mongo <ul><li>Connect </li></ul><ul><ul><li>$mongo = new Mongo(localhost:27017); </li></ul></ul><ul><ul><li>$db = $mo...
Pecl Mongo <ul><li>Insert data </li></ul><ul><li>Array( </li></ul><ul><li>'title' => 'hello', </li></ul><ul><li>'body' => ...
Pecl Mongo DEMO
Cake Mongo MongoDB + CakePHP
Cake Mongo <ul><li>MongoDB Datasource for Cakephp </li></ul><ul><ul><li>My project, start 2010/1/16 </li></ul></ul><ul><ul...
Cake Mongo DEMO
Thank you!
show dbs use hogedb show collections ichikawa={name:'ichikawa', lang:['php','perl']} db.users.save(ichikawa) yasushi={name...
<?php //MongoDB find sample $mongo = new Mongo('localhost:27017'); $db = $mongo->selectDB('phpstudy'); $collection = $db->...
<?php //mongoDB insert sample $mongo = new Mongo('localhost:27017'); $db = $mongo->selectDB('phpstudy'); $collection = $db...
Upcoming SlideShare
Loading in...5
×

PhpstudyTokyo MongoDB PHP CakePHP

6,833

Published on

PhpstudyTokyo Slides
MongoDB + PHP(pecl mongo) + CakePHP(Datasource)

Published in: Technology
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,833
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

Transcript of "PhpstudyTokyo MongoDB PHP CakePHP"

  1. 1. 2010/1/30 PHP Study Tokyo #49 Yasushi Ichikawa (id:cakephper) ‏ (id:ichikaway) MongoDB + PHP + Cake
  2. 2. self-introduction Yasushi Ichikawa Twitter: @cakephper Twitter: @ichikaway Blog English http://cake.eizoku.com/blog/ Japanese http://d.hatena.ne.jp/cakephper http://d.hatena.ne.jp/ichikaway
  3. 3. TOPIC 1. MongoDB 2. PHP + MongoDB 3. CakePHP + MongoDB
  4. 4. MongoDB <ul><li>Open-source non-relational DB </li></ul><ul><ul><li>Scalable </li></ul></ul><ul><ul><li>Schema less </li></ul></ul><ul><ul><li>Queryable </li></ul></ul><ul><li>Company: 10gen </li></ul><ul><li>Download </li></ul><ul><ul><ul><li>http://www.mongodb.org/display/DOCS/Downloads </li></ul></ul></ul>
  5. 5. MongoDB <ul><li>Term </li></ul><ul><li>Table = Collection </li></ul><ul><li>Row = Document </li></ul>
  6. 6. MongoDB <ul><li>Not replace all RDB </li></ul><ul><li>Mongo not Fit </li></ul><ul><ul><li>Need join, Transaction </li></ul></ul><ul><ul><li>Small disk space </li></ul></ul><ul><ul><ul><li>each record has field name and value </li></ul></ul></ul><ul><li>Mongo Fit </li></ul><ul><ul><li>Need Performance, Scale </li></ul></ul><ul><ul><li>Develop quickly </li></ul></ul>
  7. 7. MongoDB <ul><li>Performance </li></ul><ul><ul><li>Business insider </li></ul></ul><ul><ul><ul><li>http://www.businessinsider.com/how-we-use-mongodb-2009-11 </li></ul></ul></ul><ul><ul><li>Over 600,000 PV / business day </li></ul></ul><ul><ul><ul><li>3 apache + 1 mongoDB </li></ul></ul></ul><ul><ul><ul><li>MongoDB uses under 5% cpu time </li></ul></ul></ul>
  8. 8. MongoDB <ul><li>Schema less </li></ul><ul><ul><li>Document: bson (similar json) </li></ul></ul><ul><ul><ul><li>Binary data </li></ul></ul></ul><ul><ul><li>different schema in same collection </li></ul></ul>Posts collection Id, title, body Id, name, tel, fax Id, name, nickname, email
  9. 9. MongoDB <ul><li>RDB schema </li></ul><ul><ul><li>Natural data structure?? </li></ul></ul>Blog Title Text tag1,tag2,tag3 Comment1 Comment2 Comment3 PC Screen RDB Blog table Title Text Tags table Tag1 Tag2 Tag3 Comment Table Comment1 Comment2 Comment3
  10. 10. MongoDB <ul><li>Schema less </li></ul><ul><ul><li>Natural data structure </li></ul></ul>Blog collection Title : xxxx Text : yyyy Tag: [tag1,tag2,tag3] Comment: [comment1, comment2, comment3 ] PC Screen Mongo Blog Title Text tag1,tag2,tag3 Comment1 Comment2 Comment3
  11. 11. MongoDB DEMO
  12. 12. Pecl Mongo MongoDB + PHP
  13. 13. Pecl Mongo <ul><li>Pecl Mongo </li></ul><ul><ul><li>pecl install mongo </li></ul></ul><ul><ul><li>php.ini extension=mongo.so </li></ul></ul><ul><ul><li>http://us2.php.net/mongo </li></ul></ul>
  14. 14. Pecl Mongo <ul><li>Connect </li></ul><ul><ul><li>$mongo = new Mongo(localhost:27017); </li></ul></ul><ul><ul><li>$db = $mongo->selectDB('blog'); </li></ul></ul><ul><li>select collection </li></ul><ul><ul><li>$collection = $db->selectCollection('posts'); </li></ul></ul><ul><li>Find </li></ul><ul><ul><li>$collection->find($cond, $filed) </li></ul></ul><ul><li>->sort()->limit(5)->skip(); </li></ul><ul><li>Insert </li></ul><ul><ul><li>$collection->insert($data); </li></ul></ul><ul><li>Update </li></ul><ul><ul><li>$newdata = array(' $set ' => $data); </li></ul></ul><ul><ul><li>$collection->update($cond, $newdata); </li></ul></ul>
  15. 15. Pecl Mongo <ul><li>Insert data </li></ul><ul><li>Array( </li></ul><ul><li>'title' => 'hello', </li></ul><ul><li>'body' => 'fine day, nice!', </li></ul><ul><li>'tag' => array('tag1', 'tag2', 'tag3'), </li></ul><ul><li>'comment' => array('cmt1', 'cmt2'), </li></ul><ul><li>); </li></ul>
  16. 16. Pecl Mongo DEMO
  17. 17. Cake Mongo MongoDB + CakePHP
  18. 18. Cake Mongo <ul><li>MongoDB Datasource for Cakephp </li></ul><ul><ul><li>My project, start 2010/1/16 </li></ul></ul><ul><ul><ul><li>mongodb.org link it </li></ul></ul></ul><ul><ul><li>Version 0.1 release, 0.2 branch </li></ul></ul><ul><ul><li>Easy to Use, like using mysql datasource </li></ul></ul>http://github.com/ichikaway/mongoDB-Datasource
  19. 19. Cake Mongo DEMO
  20. 20. Thank you!
  21. 21. show dbs use hogedb show collections ichikawa={name:'ichikawa', lang:['php','perl']} db.users.save(ichikawa) yasushi={name:'yasushi', lang:['japanese','english']} db.users.save(yasushi) db.users.count() db.users.find({name:&quot;ichikawa&quot;}) db.users.find({lang:&quot;english&quot;}) db.users.update({name:&quot;ichikawa&quot;}, {&quot;$push&quot;:{lang:&quot;javascript&quot;}}) db.users.update({name:&quot;ichikawa&quot;}, {&quot;$pop&quot;:{lang:&quot;&quot;}}) db.posts.drop() db.dropDatabase()
  22. 22. <?php //MongoDB find sample $mongo = new Mongo('localhost:27017'); $db = $mongo->selectDB('phpstudy'); $collection = $db->selectCollection('posts'); $cond = array('tag' => 'tag9'); $field = array(); $result = $collection->find($cond, $field); $results = null; while ($result->hasNext()) { $mongodata = $result->getNext(); if (is_object($mongodata['_id'])) { $mongodata['_id'] = $mongodata['_id']->__toString(); } $results[][$model->alias] = $mongodata; } print_r($results); $mongo->close;
  23. 23. <?php //mongoDB insert sample $mongo = new Mongo('localhost:27017'); $db = $mongo->selectDB('phpstudy'); $collection = $db->selectCollection('posts'); $data = array( 'title' => 'hello', 'body' => 'world', 'tag' => array('tag1', 'tag2'), ); $collection->insert($data); $mongo->close;

×