PageRenderTime 43ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/Downloads/attachments/MongoDB For Beginners_ Setting up MongoDB For PHP_1.html

https://github.com/91mobiles/abc
HTML | 869 lines | 655 code | 124 blank | 90 comment | 0 complexity | efe20a730ceb9f851fa2344fe79b3b4e MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <!DOCTYPE html>
  2. <html class=" js canvas canvastext geolocation crosswindowmessaging no-websqldatabase indexeddb hashchange historymanagement draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow opacity cssanimations csscolumns cssgradients no-cssreflections csstransforms no-csstransforms3d csstransitions video audio localstorage sessionstorage webworkers applicationcache svg smil svgclippaths fontface" xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml"><head profile="http://gmpg.org/xfn/11">
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. <meta property="fb:admins" content="763699465">
  5. <meta property="og:url" content="http://www.hongkiat.com/blog/webdev-with-mongodb-part3/">
  6. <meta property="og:title" content="MongoDB For Beginners: Setting up MongoDB For PHP (Part 3/3)">
  7. <meta property="og:description" content="Before diving into this, I recommend that you read the following related articles if you have not: Introduction to MongoDB Basic MongoDB shell commands The MongoDB server is built to already work with your current web server. The problem is that you’ll need to install drivers for your preferred backend ... Continue reading »">
  8. <meta property="og:type" content="article">
  9. <meta property="og:image" content="http://media02.hongkiat.com/webdev-with-mongodb-part1/mongodb-logo.jpg">
  10. <title>MongoDB For Beginners: Setting up MongoDB For PHP</title>
  11. <link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/css.css" rel="stylesheet" type="text/css">
  12. <link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/style.css" rel="stylesheet" type="text/css" media="screen, projection">
  13. <link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/print.css" rel="stylesheet" type="text/css" media="print">
  14. <!--[if IE]><link rel='stylesheet' href="http://static04.hongkiat.com/v5/css/ie.css" type='text/css' media='screen, projection'><![endif]-->
  15. <!-- google dfp -->
  16. <script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/a_003.html" async=""></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/ps.js" async="" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/ping.asc" async="" type="text/javascript"></script><script async="" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/cbgapi.loaded_1"></script><script async="" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/cbgapi.loaded_0"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/load.js" async=""></script><script gapi_processed="true" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/plusone.js" async="" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/all_002.js" id="facebook-jssdk"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/gpt.js" type="text/javascript" async=""></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/start-5c5c650d27.js" async="" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/beacon.js" async=""></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/quant.js" async="" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/p-9dsZX-5zhUuTg.js" async="" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/beacon.js" async=""></script><script async="" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/dfp-lib.js" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/widgets.js" async="" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/widgets_002.js" id="twitter-wjs"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/ga.js" async="" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/google_service.js" type="text/javascript"></script>
  17. <script type="text/javascript">
  18. GS_googleAddAdSenseService("ca-pub-8918970543424762");
  19. GS_googleEnableAllServices();
  20. </script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/google_ads.js"></script>
  21. <script type="text/javascript">
  22. GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_145x120-01");
  23. GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_145x120-02");
  24. GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_145x120-03");
  25. GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_sidebar_all_top-right_300x250");
  26. </script>
  27. <script type="text/javascript">GA_googleFetchAds();</script>
  28. <!-- google dfp -->
  29. <link rel="alternate" type="application/rss+xml" title="Hongkiat.com RSS Feed" href="http://feeds2.feedburner.com/24thfloor">
  30. <link rel="pingback" href="http://www.hongkiat.com/blog/xmlrpc.php">
  31. <link rel="shortcut icon" href="http://mediatemplestatic.hongkiat.netdna-cdn.com/logo/hkdc/favicon.ico">
  32. <script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/jquery_002.js"></script>
  33. <script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/jquery-ui.js"></script>
  34. <script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/include-top.js"></script>
  35. <link rel="alternate" type="application/rss+xml" title="hongkiat.com » MongoDB For Beginners: Setting up MongoDB For PHP (Part 3/3) Comments Feed" href="http://www.hongkiat.com/blog/webdev-with-mongodb-part3/feed/">
  36. <script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/jquery.js"></script>
  37. <link rel="prev" title="Cartoonize Your Face With IMadeFace iPhone App" href="http://www.hongkiat.com/blog/cartoonize-face-with-imadeface/">
  38. <link rel="next" title="WordPress Job Board Themes And Plugins – Best Of" href="http://www.hongkiat.com/blog/wp-job-board-themes-plugins/">
  39. <link rel="canonical" href="http://www.hongkiat.com/blog/webdev-with-mongodb-part3/">
  40. <link rel="shortlink" href="http://www.hongkiat.com/blog/?p=16530">
  41. <link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/SyntaxHighlighter.css" type="text/css" rel="stylesheet">
  42. <!--Plugin WP Missed Schedule 2013.1024.8888 Active - Tag 6d807758f47abdb4ae626b9fa261d2f5-->
  43. <!-- All in One SEO Pack 2.0.4 by Michael Torbert of Semper Fi Web Design[1034,1123] -->
  44. <meta name="description" content="Before diving into this, I recommend that you read the following related articles if you have not: Introduction to MongoDB Basic MongoDB shell">
  45. <meta name="keywords" content="web design">
  46. <!-- /all in one seo pack -->
  47. <script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/osd.js" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/pubads_impl_40.js" type="text/javascript" async=""></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/embed.js" async="" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/bsa.js" async="" type="text/javascript"></script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/count.js" type="text/javascript" async=""></script><script async="async" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/s_9d66286b452642a759aabeac9d39d265.js" id="_bsap_js_9d66286b452642a759aabeac9d39d265" type="text/javascript"></script><style type="text/css">.fb_hidden{position:absolute;top:-10000px;z-index:10001}.fb_invisible{display:none}.fb_reset{background:none;border:0;border-spacing:0;color:#000;cursor:auto;direction:ltr;font-family:"lucida grande", tahoma, verdana, arial, sans-serif;font-size:11px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:1;margin:0;overflow:visible;padding:0;text-align:left;text-decoration:none;text-indent:0;text-shadow:none;text-transform:none;visibility:visible;white-space:normal;word-spacing:normal}.fb_reset>div{overflow:hidden}.fb_link img{border:none}
  48. .fb_dialog{background:rgba(82, 82, 82, .7);position:absolute;top:-10000px;z-index:10001}.fb_reset .fb_dialog_legacy{overflow:visible}.fb_dialog_advanced{padding:10px;-moz-border-radius:8px;-webkit-border-radius:8px;border-radius:8px}.fb_dialog_content{background:#fff;color:#333}.fb_dialog_close_icon{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/yq/r/IE9JII6Z1Ys.png) no-repeat scroll 0 0 transparent;_background-image:url(http://static.ak.fbcdn.net/rsrc.php/v2/yL/r/s816eWC-2sl.gif);cursor:pointer;display:block;height:15px;position:absolute;right:18px;top:17px;width:15px}.fb_dialog_mobile .fb_dialog_close_icon{top:5px;left:5px;right:auto}.fb_dialog_padding{background-color:transparent;position:absolute;width:1px;z-index:-1}.fb_dialog_close_icon:hover{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/yq/r/IE9JII6Z1Ys.png) no-repeat scroll 0 -15px transparent;_background-image:url(http://static.ak.fbcdn.net/rsrc.php/v2/yL/r/s816eWC-2sl.gif)}.fb_dialog_close_icon:active{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/yq/r/IE9JII6Z1Ys.png) no-repeat scroll 0 -30px transparent;_background-image:url(http://static.ak.fbcdn.net/rsrc.php/v2/yL/r/s816eWC-2sl.gif)}.fb_dialog_loader{background-color:#f2f2f2;border:1px solid #606060;font-size:24px;padding:20px}.fb_dialog_top_left,.fb_dialog_top_right,.fb_dialog_bottom_left,.fb_dialog_bottom_right{height:10px;width:10px;overflow:hidden;position:absolute}.fb_dialog_top_left{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/ye/r/8YeTNIlTZjm.png) no-repeat 0 0;left:-10px;top:-10px}.fb_dialog_top_right{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/ye/r/8YeTNIlTZjm.png) no-repeat 0 -10px;right:-10px;top:-10px}.fb_dialog_bottom_left{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/ye/r/8YeTNIlTZjm.png) no-repeat 0 -20px;bottom:-10px;left:-10px}.fb_dialog_bottom_right{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/ye/r/8YeTNIlTZjm.png) no-repeat 0 -30px;right:-10px;bottom:-10px}.fb_dialog_vert_left,.fb_dialog_vert_right,.fb_dialog_horiz_top,.fb_dialog_horiz_bottom{position:absolute;background:#525252;filter:alpha(opacity=70);opacity:.7}.fb_dialog_vert_left,.fb_dialog_vert_right{width:10px;height:100%}.fb_dialog_vert_left{margin-left:-10px}.fb_dialog_vert_right{right:0;margin-right:-10px}.fb_dialog_horiz_top,.fb_dialog_horiz_bottom{width:100%;height:10px}.fb_dialog_horiz_top{margin-top:-10px}.fb_dialog_horiz_bottom{bottom:0;margin-bottom:-10px}.fb_dialog_iframe{line-height:0}.fb_dialog_content .dialog_title{background:#6d84b4;border:1px solid #3b5998;color:#fff;font-size:14px;font-weight:bold;margin:0}.fb_dialog_content .dialog_title>span{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/yd/r/Cou7n-nqK52.gif) no-repeat 5px 50%;float:left;padding:5px 0 7px 26px}body.fb_hidden{-webkit-transform:none;height:100%;margin:0;overflow:visible;position:absolute;top:-10000px;left:0;width:100%}.fb_dialog.fb_dialog_mobile.loading{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/ya/r/3rhSv5V8j3o.gif) white no-repeat 50% 50%;min-height:100%;min-width:100%;overflow:hidden;position:absolute;top:0;z-index:10001}.fb_dialog.fb_dialog_mobile.loading.centered{max-height:590px;min-height:590px;max-width:500px;min-width:500px}#fb-root #fb_dialog_ipad_overlay{background:rgba(0, 0, 0, .45);position:absolute;left:0;top:0;width:100%;min-height:100%;z-index:10000}#fb-root #fb_dialog_ipad_overlay.hidden{display:none}.fb_dialog.fb_dialog_mobile.loading iframe{visibility:hidden}.fb_dialog_content .dialog_header{-webkit-box-shadow:white 0 1px 1px -1px inset;background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#738ABA), to(#2C4987));border-bottom:1px solid;border-color:#1d4088;color:#fff;font:14px Helvetica, sans-serif;font-weight:bold;text-overflow:ellipsis;text-shadow:rgba(0, 30, 84, .296875) 0 -1px 0;vertical-align:middle;white-space:nowrap}.fb_dialog_content .dialog_header table{-webkit-font-smoothing:subpixel-antialiased;height:43px;width:100%}.fb_dialog_content .dialog_header td.header_left{font-size:12px;padding-left:5px;vertical-align:middle;width:60px}.fb_dialog_content .dialog_header td.header_right{font-size:12px;padding-right:5px;vertical-align:middle;width:60px}.fb_dialog_content .touchable_button{background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#4966A6), color-stop(.5, #355492), to(#2A4887));border:1px solid #29447e;-webkit-background-clip:padding-box;-webkit-border-radius:3px;-webkit-box-shadow:rgba(0, 0, 0, .117188) 0 1px 1px inset, rgba(255, 255, 255, .167969) 0 1px 0;display:inline-block;margin-top:3px;max-width:85px;line-height:18px;padding:4px 12px;position:relative}.fb_dialog_content .dialog_header .touchable_button input{border:none;background:none;color:#fff;font:12px Helvetica, sans-serif;font-weight:bold;margin:2px -12px;padding:2px 6px 3px 6px;text-shadow:rgba(0, 30, 84, .296875) 0 -1px 0}.fb_dialog_content .dialog_header .header_center{color:#fff;font-size:16px;font-weight:bold;line-height:18px;text-align:center;vertical-align:middle}.fb_dialog_content .dialog_content{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/y9/r/jKEcVPZFk-2.gif) no-repeat 50% 50%;border:1px solid #555;border-bottom:0;border-top:0;height:150px}.fb_dialog_content .dialog_footer{background:#f2f2f2;border:1px solid #555;border-top-color:#ccc;height:40px}#fb_dialog_loader_close{float:left}.fb_dialog.fb_dialog_mobile .fb_dialog_close_button{text-shadow:rgba(0, 30, 84, .296875) 0 -1px 0}.fb_dialog.fb_dialog_mobile .fb_dialog_close_icon{visibility:hidden}
  49. .fb_iframe_widget{display:inline-block;position:relative}.fb_iframe_widget span{display:inline-block;position:relative;text-align:justify}.fb_iframe_widget iframe{position:absolute}.fb_iframe_widget_lift{z-index:1}.fb_hide_iframes iframe{position:relative;left:-10000px}.fb_iframe_widget_loader{position:relative;display:inline-block}.fb_iframe_widget_fluid{display:inline}.fb_iframe_widget_fluid span{width:100%}.fb_iframe_widget_loader iframe{min-height:32px;z-index:2;zoom:1}.fb_iframe_widget_loader .FB_Loader{background:url(http://static.ak.fbcdn.net/rsrc.php/v2/y9/r/jKEcVPZFk-2.gif) no-repeat;height:32px;width:32px;margin-left:-16px;position:absolute;left:50%;z-index:4}
  50. .fb_connect_bar_container div,.fb_connect_bar_container span,.fb_connect_bar_container a,.fb_connect_bar_container img,.fb_connect_bar_container strong{background:none;border-spacing:0;border:0;direction:ltr;font-style:normal;font-variant:normal;letter-spacing:normal;line-height:1;margin:0;overflow:visible;padding:0;text-align:left;text-decoration:none;text-indent:0;text-shadow:none;text-transform:none;visibility:visible;white-space:normal;word-spacing:normal;vertical-align:baseline}.fb_connect_bar_container{position:fixed;left:0 !important;right:0 !important;height:42px !important;padding:0 25px !important;margin:0 !important;vertical-align:middle !important;border-bottom:1px solid #333 !important;background:#3b5998 !important;z-index:99999999 !important;overflow:hidden !important}.fb_connect_bar_container_ie6{position:absolute;top:expression(document.compatMode=="CSS1Compat"? document.documentElement.scrollTop+"px":body.scrollTop+"px")}.fb_connect_bar{position:relative;margin:auto;height:100%;width:100%;padding:6px 0 0 0 !important;background:none;color:#fff !important;font-family:"lucida grande", tahoma, verdana, arial, sans-serif !important;font-size:13px !important;font-style:normal !important;font-variant:normal !important;font-weight:normal !important;letter-spacing:normal !important;line-height:1 !important;text-decoration:none !important;text-indent:0 !important;text-shadow:none !important;text-transform:none !important;white-space:normal !important;word-spacing:normal !important}.fb_connect_bar a:hover{color:#fff}.fb_connect_bar .fb_profile img{height:30px;width:30px;vertical-align:middle;margin:0 6px 5px 0}.fb_connect_bar div a,.fb_connect_bar span,.fb_connect_bar span a{color:#bac6da;font-size:11px;text-decoration:none}.fb_connect_bar .fb_buttons{float:right;margin-top:7px}
  51. .fbpluginrecommendationsbarleft,.fbpluginrecommendationsbarright{position:fixed !important;bottom:0;z-index:999}.fbpluginrecommendationsbarleft{left:10px}.fbpluginrecommendationsbarright{right:10px}</style><style id="bsa_css" type="text/css">div.bsap_1235460{width:100%;display:block}div.bsap_1235460 a{width:468px}div.bsap_1235460 a img{padding:0}div.bsap_1235460 a em{font-style:normal}div.bsap_1235460 a{font-size:11px;color:#888;font-family:verdana,sans-serif;text-align:center;text-decoration:none;overflow:hidden;float:right;float:left;}div.bsap_1235460 img{border:0;clear:right;}div.bsap_1235460 a.adhere{color:#666;font-weight:bold;font-size:12px;border:1px solid #ccc;background:#e7e7e7;text-align:center;}div.bsap_1235460 a.adhere:hover{border:1px solid #999;background:#ddd;color:#333;}div.bsap_1235460 a{line-height:100%}div.bsap_1235460 a.adhere{width:468px;height:60px;line-height:480%}html>body div.bsap_1235460 a.adhere{width:466px;height:58px}div.bsap_1235460 img.s{height:0;width:0}div.bsap_1237809{width:100%;display:block}div.bsap_1237809 a{width:300px}div.bsap_1237809 a img{padding:0}div.bsap_1237809 a em{font-style:normal}div.bsap_1237809 a{display:block;font-size:11px;margin-top:10px;color:#888;font-family:verdana,sans-serif;text-align:center;text-decoration:none;overflow:hidden;float:left;}div.bsap_1237809 img{border:0;clear:right;}div.bsap_1237809 a.adhere{color:#666;font-weight:bold;font-size:12px;border:1px solid #ccc;background:#e7e7e7;text-align:center;}div.bsap_1237809 a.adhere:hover{border:1px solid #999;background:#ddd;color:#333;}div.bsap_1237809 iframe{display:block;font-size:11px;margin-top:10px;color:#888;font-family:verdana,sans-serif;text-align:center;text-decoration:none;overflow:hidden;float:left;}div.bsap_1237809 a{line-height:100%}div.bsap_1237809 a.adhere{width:300px;height:120px;line-height:960%}html>body div.bsap_1237809 a.adhere{width:298px;height:118px}div.bsap_1237809 img.s{height:0;width:0}div.bsap_1247679{width:100%;display:block}div.bsap_1247679 a{width:500px}div.bsap_1247679 a img{padding:0}div.bsap_1247679 a em{font-style:normal}div.bsap_1247679 a{display:block;font-size:11px;color:#888;font-family:verdana,sans-serif;margin:0 4px 10px 0;text-align:center;text-decoration:none;overflow:hidden;float:left;}div.bsap_1247679 img{border:0;clear:right;}div.bsap_1247679 a.adhere{color:#666;font-weight:bold;font-size:12px;border:1px solid #ccc;background:#e7e7e7;text-align:center;}div.bsap_1247679 a.adhere:hover{border:1px solid #999;background:#ddd;color:#333;}div.bsap_1247679 a{line-height:100%}div.bsap_1247679 a.adhere{width:500px;height:100px;line-height:800%}html>body div.bsap_1247679 a.adhere{width:498px;height:98px}div.bsap_1247679 img.s{height:0;width:0}div.bsap_1249810{width:100%;display:block}div.bsap_1249810 a{width:300px}div.bsap_1249810 a img{padding:0}div.bsap_1249810 a em{font-style:normal}div.bsap_1249810 a{display:block;font-size:11px;color:#888;font-family:verdana,sans-serif;margin:0 4px 10px 0;text-align:center;text-decoration:none;overflow:hidden;float:left;}div.bsap_1249810 img{border:0;clear:right;}div.bsap_1249810 a.adhere{color:#666;font-weight:bold;font-size:12px;border:1px solid #ccc;background:#e7e7e7;text-align:center;}div.bsap_1249810 a.adhere:hover{border:1px solid #999;background:#ddd;color:#333;}div.bsap_1249810 a{line-height:100%}div.bsap_1249810 a.adhere{width:300px;height:250px;line-height:2000%}html>body div.bsap_1249810 a.adhere{width:298px;height:248px}div.bsap_1249810 img.s{height:0;width:0}</style></head>
  52. <body style="" data-twttr-rendered="true"><div id="crowdscience_invitation" style="z-index: 150000; position: fixed; right: 50px; overflow: hidden; bottom: 0px; visibility: visible; height: 211px; display: none;"> <table style="width:auto; margin:0; padding:0; border:none; border-collapse:collapse;"> <tbody> <tr> <td style="background:url(http://static.crowdscience.com/inv/tl.png); height:10px; width:10px; overflow:hidden; padding:0;"></td> <td style="background:url(http://static.crowdscience.com/inv/b.png);"></td> <td style="background:url(http://static.crowdscience.com/inv/tr.png); height:10px; width:10px; overflow:hidden; padding:0;"></td> </tr> <tr> <td style="background:url(http://static.crowdscience.com/inv/b.png);"></td> <td id="crowdscience_invitation_inner" style="background-color: rgb(255, 255, 255); padding: 10px; width: 360px; border-width: 1px 1px medium; border-style: solid solid none; border-color: rgb(102, 102, 102) rgb(102, 102, 102) -moz-use-text-color; -moz-border-top-colors: none; -moz-border-right-colors: none; -moz-border-bottom-colors: none; -moz-border-left-colors: none; border-image: none;"> <p style="text-align:left; margin:5px 0 10px; padding:0;"> <img style="min-height: 0px;" id="crowdscience_invitation_logo" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/default-logo.gif"> </p> <p style="text-align:left; font:13px Helvetica,Arial,Sans Serif; color:#000; margin:10px 0; padding:0;">
  53. Hongkiat is conducting research
  54. to better understand and meet the needs of the users of their site.
  55. Would you like to participate? </p> <p style="text-align:center; font:18px Helvetica,Arial,Sans Serif; color:#000; margin:15px 0 20px; padding:0;"> <a href="#" style="font-size:18px;font-weight:bold;color:#E58712;" onclick="CrowdScience.onAccept(); return false">Yes, I'll help</a> <span style="font-size:13px;">or</span> <a href="#" style="font-size:18px;font-weight:bold; color:#999;" onclick="CrowdScience.onDecline(); return false">No thanks</a> </p> <p style="text-align:left; font:13px Helvetica,Arial,Sans Serif; color:#000; margin:10px 0 10px; padding:0;"> Responses are anonymous, view our <a style="font-size:13px;color:#E58712;" href="http://app.crowdscience.com/privacy/survey/" target="_blank" onclick="CrowdScience.extendHideTimeout();">privacy policy</a>. </p> </td> <td style="background:url(http://static.crowdscience.com/inv/b.png);"></td> </tr> </tbody> </table> <img src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/a.gif" style="height: 0px; width: 0px; display: none;"></div><div id="itxtexclude"><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/init.js"></script><link rel="stylesheet" type="text/css" href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/itxtcss_1396281479.css" id="itxtcss"><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/ui_mobile_1395261999.js"></script><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/ui_1400841935.js"></script><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/tmpl_1395261999.js"></script><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/metrics_1395261999.js"></script><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/itxt_1395261999.js"></script><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/fx2_1395261999.js"></script><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/fx_1395261999.js"></script><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/debug_1395261999.js"></script><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/data_1400710318.js"></script><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/core_1400590916.js"></script><script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/underscore-min-ns-1.js"></script></div>
  56. <a name="top"></a>
  57. <!-- stats -->
  58. <script type="text/javascript">var _gaq=_gaq||[];_gaq.push(["_setAccount","UA-275126-1"]);_gaq.push(["_trackPageview"]);(function(){var b=document.createElement("script");b.type="text/javascript";b.async=true;b.src=("https:"==document.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(b,a)})();</script>
  59. <!-- stats -->
  60. <!-- sticky header -->
  61. <div style="top: 0px;" id="hSlideContainer">
  62. <div id="hSlideContent">
  63. <ul id="sliderLeft">
  64. <li class="hkdc_logo"><a href="http://www.hongkiat.com/blog/#top">Back to Home, top</a></li>
  65. <li id="hPrevNext">
  66. <div class="prev"><a href="http://www.hongkiat.com/blog/wp-job-board-themes-plugins/" rel="next">prev</a> </div>
  67. <div class="next"><a href="http://www.hongkiat.com/blog/cartoonize-face-with-imadeface/" rel="prev">next</a> </div>
  68. </li>
  69. <li class="sharetxt">Share this post - </li>
  70. <li class="fb"><div><iframe src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/like.html" scrolling="no" style="border:none; overflow:hidden; width:100px; height:21px;" allowtransparency="true" frameborder="0"></iframe></div></li>
  71. <li class="twitter"><div><iframe style="width: 106px; height: 20px;" data-twttr-rendered="true" title="Twitter Tweet Button" class="twitter-share-button twitter-tweet-button twitter-share-button twitter-count-horizontal" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/tweet_button.html" allowtransparency="true" scrolling="no" id="twitter-widget-0" frameborder="0"></iframe><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></div></li>
  72. <li class="gplus"><div><div id="___plusone_0" style="text-indent: 0px; margin: 0px; padding: 0px; background: none repeat scroll 0% 0% transparent; border-style: none; float: none; line-height: normal; font-size: 1px; vertical-align: baseline; display: inline-block; width: 90px; height: 20px;"><iframe title="+1" data-gapiattached="true" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/fastbutton.html" name="I2_1402471330215" id="I2_1402471330215" vspace="0" tabindex="0" style="position: static; top: 0px; width: 90px; margin: 0px; border-style: none; left: 0px; visibility: visible; height: 20px;" scrolling="no" marginwidth="0" marginheight="0" hspace="0" frameborder="0" width="100%"></iframe></div></div></li>
  73. <li class="su"><div><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/hostedbadge.html"></script><iframe id="iframe-stmblpn-widget-1" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/a.html" style="overflow: hidden; margin: 0px; padding: 0px; border: 0px none;" allowtransparency="true" scrolling="no" frameborder="0" height="18" width="18"></iframe> <script type="text/javascript"> (function() { var li = document.createElement('script'); li.type = 'text/javascript'; li.async = true; li.src = window.location.protocol + '//platform.stumbleupon.com/1/widgets.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(li, s); })(); </script></div></li>
  74. </ul>
  75. <ul id="sliderRight">
  76. <li class="searchbox">
  77. <form id="searchform" method="get" action="/blog/search">
  78. <input name="q" id="s" class="search" placeholder="E.g. Free vectors" type="text">
  79. </form>
  80. </li>
  81. <li class="btt"><a href="#top" title="Back to top"></a></li>
  82. </ul>
  83. </div>
  84. </div>
  85. <!-- sticky header -->
  86. <!-- header type #1 -->
  87. <div id="headerbanner01" class="clearfix">
  88. <div class="headerbanner_wrap clearfix">
  89. <div class="s728">
  90. <script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/4724.js"></script><div id="div-fm-gpt-zone-4724"><div style="border: 0pt none;" id="google_ads_iframe_/4601/fmpub.hongkiat_0__container__"><iframe src="javascript:&quot;<html><body style='background:transparent'></body></html>&quot;" style="border: 0px none; vertical-align: bottom;" marginheight="0" marginwidth="0" scrolling="no" name="google_ads_iframe_/4601/fmpub.hongkiat_0" id="google_ads_iframe_/4601/fmpub.hongkiat_0" frameborder="0" height="90" width="728"></iframe></div><iframe src="javascript:&quot;<html><body style='background:transparent'></body></html>&quot;" style="border: 0px none; vertical-align: bottom; visibility: hidden; display: none;" marginheight="0" marginwidth="0" scrolling="no" name="google_ads_iframe_/4601/fmpub.hongkiat_0__hidden__" id="google_ads_iframe_/4601/fmpub.hongkiat_0__hidden__" frameborder="0" height="0" width="0"></iframe></div>
  91. </div>
  92. <div class="s230">
  93. <iframe src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/230x90.html" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" style="" scrolling="no" frameborder="0" height="90" width="230"></iframe>
  94. </div>
  95. </div>
  96. </div>
  97. <!-- header type #1 -->
  98. <!-- header start -->
  99. <div id="header" class="clearfix">
  100. <div class="logorow clearfix">
  101. <div class="thelogo">
  102. <h1><a href="http://www.hongkiat.com/blog/">hongkiat.com</a></h1>
  103. </div>
  104. <div class="thebanner">
  105. <!-- BuySellAds Zone Code -->
  106. <div id="bsap_1235460" class="bsap_1235460 bsap"><a href="http://stats.buysellads.com/click.go?z=1235460&amp;b=4754618&amp;g=&amp;s=&amp;sw=1366&amp;sh=768&amp;br=firefox,29,linux&amp;r=0.3205651984819403&amp;link=http://imcreator.com/?utm_source=hongkiat&amp;utm_medium=banner&amp;utm_content=space" onmouseover="window.status = 'http://imcreator.com/?utm_source=hongkiat&amp;utm_medium=banner&amp;utm_content=space'; return true;" onmouseout="window.status=''; return true;" class="ad1 odd" title="Design Your Website" id="bsa_4754618" target="_blank"><img src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/222592-1400150575.jpg" alt="Design Your Website" height="60" width="468"></a></div>
  107. <!-- End BuySellAds Zone Code -->
  108. </div>
  109. </div>
  110. <div class="navirow clearfix">
  111. <ul class="sf-menu sf-js-enabled">
  112. <li class="home"> <a class="sf-with-ul" href="http://www.hongkiat.com/blog/">Home<span class="sf-sub-indicator"> »</span></a>
  113. <ul style="display: none; visibility: hidden;">
  114. <li><a href="http://www.hongkiat.com/blog/about-us/">About Us</a></li>
  115. <li><a href="http://www.hongkiat.com/blog/advertise/">Advertise</a></li>
  116. <li><a href="http://www.hongkiat.com/blog/contact/">Contact us</a></li>
  117. <li><a href="http://www.hongkiat.com/blog/write-for-us/">Become an author</a></li>
  118. <li><a href="http://www.hongkiat.com/blog/submit-news-tips/">Submit tips</a></li>
  119. </ul>
  120. </li>
  121. <li class=" photoshop"><a href="http://www.hongkiat.com/blog/category/photoshop/">Photoshop</a></li>
  122. <li class=" icons"><a href="http://www.hongkiat.com/blog/category/free-icons/">Icons</a></li>
  123. <li class="active design"><a href="http://www.hongkiat.com/blog/category/design/">Design</a></li>
  124. <li class=" wordpress"><a href="http://www.hongkiat.com/blog/category/wordpress/">WordPress</a></li>
  125. <li class=" tools"><a href="http://www.hongkiat.com/blog/category/tools/">Tools</a></li>
  126. <li class=" inspiration"><a href="http://www.hongkiat.com/blog/category/inspiration/">Inspiration</a></li>
  127. <li class=" graphics"><a href="http://www.hongkiat.com/blog/category/graphics/">Graphics</a></li>
  128. <li class=" wallpapers"><a href="http://www.hongkiat.com/blog/category/free-wallpapers/">Wallpapers</a></li>
  129. <li class=" howto"><a href="http://www.hongkiat.com/blog/category/how-to/">How-to</a></li>
  130. <li class=" web20"><a href="http://www.hongkiat.com/blog/category/web-20/">Web 2.0</a></li>
  131. <!--
  132. <li class=" freebies"><a href="/blog/category/freebies-online/">Freebies</a></li>
  133. -->
  134. <li class="deals"><a href="http://hongki.at/deals/">Deals</a></li>
  135. </ul>
  136. <div class="searchbox">
  137. <form id="searchform" method="get" action="/blog/search">
  138. <input name="q" id="s" class="search" placeholder="E.g. Free vectors" type="text">
  139. </form>
  140. </div>
  141. </div>
  142. </div>
  143. <!-- header end -->
  144. <div id="main" class="clearfix">
  145. <div class="contentwrap"><div class="content single">
  146. <div class="post clearfix" id="post-16530">
  147. <!-- google_ad_section_start -->
  148. <h1>MongoDB For Beginners: Setting up MongoDB For PHP (Part 3/3)</h1>
  149. <!-- google_ad_section_end -->
  150. <!-- post meta -->
  151. <div class="sMeta">
  152. <p>
  153. By
  154. <strong><a href="http://www.hongkiat.com/blog/author/jake/" title="Posts by Jake Rocheleau" rel="author">Jake Rocheleau</a></strong>.
  155. <span class="cat">Filed in <a href="http://www.hongkiat.com/blog/category/design/" title="View all posts in Web Design" rel="category tag">Web Design</a></span>
  156. <span class="edit"></span>
  157. </p>
  158. </div>
  159. <!-- // -->
  160. <div class="gad_wrap">
  161. <script language="JavaScript">
  162. var google_adnum = 0;
  163. function google_ad_request_done(google_ads) {
  164. var s = ''; var i;
  165. if (google_ads.length == 0) { return; }
  166. if (google_ads.length == 1) {
  167. s += '<div class=\"gad_adFeedback\"><a href=\"'+google_info.feedback_url+'\">Ads by Google</a></div><div class=\"gad_unit\"><a class=\"gad_adTitle\" href=\"'+google_ads[0].url+'\" onmouseout=\"window.status=\'\'\" onmouseover=\"window.status=\'go to '+google_ads[0].visible_url+';return true\'\"><span>'+google_ads[0].line1+'</span></a><a class=\"gad_adURL\" href=\"'+google_ads[0].url+'\" onmouseout=\"window.status=\'\'\" onmouseover=\"window.status=\'go to '+google_ads[0].visible_url+';return true\'\"><span>'+google_ads[0].visible_url+'</span></a> <span class=\"gad_adText\">'+google_ads[0].line2+' '+google_ads[0].line3+'</span></div>';
  168. }
  169. else if (google_ads.length > 1) {
  170. s += '<div class=\"gad_adFeedback\"><a href=\"' + google_info.feedback_url + '\">Ads by Google</a></div>';
  171. for(i = 0; i < google_ads.length; ++i) {
  172. s += '<div class=\"gad_unit\"><a class=\"gad_adTitle\" href=\"'+google_ads[i].url+'\" onmouseout=\"window.status=\'\'\" onmouseover=\"window.status=\'go to '+google_ads[i].visible_url+';return true\'\"><span>'+google_ads[i].line1+'</span></a><a class=\"gad_adURL\" href=\"'+google_ads[i].url+'\" onmouseout=\"window.status=\'\'\" onmouseover=\"window.status=\'go to '+google_ads[i].visible_url+';return true\'\"><span>'+google_ads[i].visible_url+'</span></a> <span class=\"gad_adText\">'+google_ads[i].line2+' '+google_ads[i].line3+'</span></div>';
  173. }
  174. }
  175. if (google_ads[0].bidtype == "CPC") {
  176. google_adnum = google_adnum + google_ads.length;
  177. }
  178. document.write(s);
  179. return;
  180. }
  181. google_ad_client = 'pub-8918970543424762';
  182. google_ad_channel = '0510687918';
  183. google_ad_output = 'js';
  184. google_max_num_ads = '1';
  185. google_ad_type = 'text';
  186. google_feedback = 'on';
  187. google_skip = google_adnum;
  188. </script>
  189. <script language="JavaScript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/show_ads.js"></script><iframe marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" style="display:none" id="google_esf" name="google_esf" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/zrt_lookup.html" frameborder="0" height="0" width="0"></iframe><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/show_ads_impl.js"></script><script language="JavaScript1.1" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/ads_002"></script><div class="gad_adFeedback"><a href="https://www.google.com/url?ct=abg&amp;q=https://www.google.com/adsense/support/bin/request.py%3Fcontact%3Dabg_afc%26url%3Dhttp://www.hongkiat.com/blog/webdev-with-mongodb-part3/%26gl%3DIN%26hl%3Den%26client%3Dca-pub-8918970543424762%26ai0%3DC88sSoQOYU6qALZCoigbppIDIA_X2rNIGveGc6KABnaP61QUQASDr-ZQDUIi82ZD7_____wFg5Zrpg-AOyAEBqQKUHx84NSNSPqgDAaoEhgFP0IVZWvt6nPEf0XXSBoYUBuhsF1buqnFwx3RHUQufIjaeJQj5eIfatRSichVmik2cErvkJeq3fdEDa2e5BWrP72VxLtjvt7QU7nTrOx9XUOiT0CjiQfmUIHG8fkMtY8Tnqjy_kpSltadz1jVWBcAh13xr7y84Qd5XdYCVCeOfAOkZmB781YAHjYXGOQ&amp;usg=AFQjCNG6DfmZ-ep56Mha4QiSqc3TZAEV9Q">Ads by Google</a></div><div class="gad_unit"><a class="gad_adTitle" href="http://googleads.g.doubleclick.net/aclk?sa=L&amp;ai=C88sSoQOYU6qALZCoigbppIDIA_X2rNIGveGc6KABnaP61QUQASDr-ZQDUIi82ZD7_____wFg5Zrpg-AOyAEBqQKUHx84NSNSPqgDAaoEhgFP0IVZWvt6nPEf0XXSBoYUBuhsF1buqnFwx3RHUQufIjaeJQj5eIfatRSichVmik2cErvkJeq3fdEDa2e5BWrP72VxLtjvt7QU7nTrOx9XUOiT0CjiQfmUIHG8fkMtY8Tnqjy_kpSltadz1jVWBcAh13xr7y84Qd5XdYCVCeOfAOkZmB781YAHjYXGOQ&amp;num=1&amp;sig=AOD64_1O7PwxpDFu8Np5tUv1WaR1TDI6yA&amp;client=ca-pub-8918970543424762&amp;adurl=http://flugtag.redbull.com/in/" onmouseout="window.status=''" onmouseover="window.status='go to www.flugtag.redbull.com/in/;return true'"><span>Defy the laws of gravity</span></a><a class="gad_adURL" href="http://googleads.g.doubleclick.net/aclk?sa=L&amp;ai=C88sSoQOYU6qALZCoigbppIDIA_X2rNIGveGc6KABnaP61QUQASDr-ZQDUIi82ZD7_____wFg5Zrpg-AOyAEBqQKUHx84NSNSPqgDAaoEhgFP0IVZWvt6nPEf0XXSBoYUBuhsF1buqnFwx3RHUQufIjaeJQj5eIfatRSichVmik2cErvkJeq3fdEDa2e5BWrP72VxLtjvt7QU7nTrOx9XUOiT0CjiQfmUIHG8fkMtY8Tnqjy_kpSltadz1jVWBcAh13xr7y84Qd5XdYCVCeOfAOkZmB781YAHjYXGOQ&amp;num=1&amp;sig=AOD64_1O7PwxpDFu8Np5tUv1WaR1TDI6yA&amp;client=ca-pub-8918970543424762&amp;adurl=http://flugtag.redbull.com/in/" onmouseout="window.status=''" onmouseover="window.status='go to www.flugtag.redbull.com/in/;return true'"><span>www.flugtag.redbull.com/in/</span></a> <span class="gad_adText">Indias 1st Red Bull Flugtag Fly with Indian Physics. Apply now.</span></div>
  190. </div>
  191. <!-- /// -->
  192. <!-- content -->
  193. <div class="sContent intxt">
  194. <!-- google_ad_section_start -->
  195. <p>Before diving into this, I recommend that you read the following related articles if you have not:</p>
  196. <ul>
  197. <li><a href="http://www.hongkiat.com/blog/webdev-with-mongodb-part1/">Introduction to MongoDB</a></li>
  198. <li><a href="http://www.hongkiat.com/blog/webdev-with-mongodb-part2/">Basic MongoDB shell commands</a></li>
  199. </ul>
  200. <p>The MongoDB server is built to already work with your current web
  201. server. The problem is that youll need to install drivers for your
  202. preferred backend language PHP, Ruby, Node.js, Perl, whatever. I wont
  203. go into the process of installing WAMP/MAMP because this is a bit off
  204. topic from Mongo.</p>
  205. <p class="sw"><img src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/mongodb-logo.jpg" height="282" width="500"></p>
  206. <p>But there are very easy-to-follow tutorials which already exist for <a href="http://www.tutorialchip.com/php/wamp-server-installation-guide-for-windows-7-3264-bits/">installing WAMP</a> and <a href="http://www.aschroder.com/2009/02/how-to-install-mamp-on-your-macbook/">installing MAMP</a> on either Operating System<strong>.</strong></p>
  207. <p><strong>Note:</strong> You can still work with your MongoDB server
  208. without a web server. But most applications would require this and
  209. thats why Im focusing primarily on MongoDB for web development.</p>
  210. <p>You can get some output from the MongoDB process by visiting the
  211. localhost address using your installations specific port number.</p>
  212. <p>MongoDB will default to <em>27017</em>. This is the driver port and to view analytics/diagnostics we want to use <em>28017</em>. So you may access the MongoDB server info on your browser by visiting:</p>
  213. <p><code>http://localhost:28017</code></p>
  214. <p>This address should still work properly regardless of your local web server being online or not.</p>
  215. <p>After you have WAMP or MAMP installed and running you can visit the
  216. localhost web server on port :80 to see the default page template.</p>
  217. <p>Now Im going to walk you through installing the PHP driver, and well finish up developing over MongoDBs PHP class library.</p>
  218. <h3>Setup the MongoDB PHP Drivers</h3>
  219. <p>Mac and Linux users should be able to install these drivers right from the command line. Looking on the MongoDB <a href="http://www.mongodb.org/display/DOCS/PHP+Language+Center">PHP language docs</a> we should install using pecl from the <a href="http://pear.php.net/">Pear Library</a> of PHP code.</p>
  220. <p>Heres the line of code you should run from terminal:</p>
  221. <div class="dp-highlighter"><ol class="dp-c" start="1"><li class="alt"><span><span>sudo&nbsp;apt-get&nbsp;install&nbsp;php5-dev&nbsp;php5-cli&nbsp;php-pear&nbsp;&nbsp;</span></span></li><li class=""><span>sudo&nbsp;pecl&nbsp;install&nbsp;mongo&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;" name="code" class="php">sudo apt-get install php5-dev php5-cli php-pear
  222. sudo pecl install mongo</pre>
  223. <p>If you already have Pear installed then you dont need to run the
  224. first line. That is only for PHP installs which are not updated to the
  225. latest Pear library. But after the commands finish locate your <strong>php.ini</strong> file and add the following bit of code:</p>
  226. <div class="dp-highlighter"><ol class="dp-c" start="1"><li class="alt"><span><span>extension=mongo.so&nbsp;&nbsp;</span></span></li></ol></div><pre style="display: none;" name="code" class="php">extension=mongo.so
  227. </pre>
  228. <p>You should notice a similar block of code somewhere midway down the
  229. file which has a slew of other lines mirroring extension=name. Most
  230. extensions are commented out but the lines without a hash symbol(#) are
  231. currently active extensions.</p>
  232. <p>After youve added this line save &amp; close the file, then restart your Apache web server for the new changes to take effect.</p>
  233. <h4>Mongo PHP Extension on Windows</h4>
  234. <p>All users on Windows will also need to edit their php.ini file. This
  235. can be accomplished directly from the WAMP context menu by clicking on
  236. the icon, then moving to PHP -&gt; php.ini. Youll need to add the same
  237. line of code except the filename should be <strong>php_mongo.dll</strong>. </p>
  238. <p>Also instead of installing through the command line its much easier
  239. to download a copy of the extension and move this over manually.</p>
  240. <p>Windows users should head over to <a href="https://github.com/mongodb/mongo-php-driver/downloads">this Github directory</a>
  241. full of MongoDB PHP drivers. Find the latest release which supports
  242. your version of PHP (5.2, 5.3, 5.4) and download the .zip. Once you
  243. extract the folder find the extension which matches your version of PHP.
  244. In my case Ill use <strong>php_mongo-1.2.12-5.3-vc9.dll</strong> and rename this to <strong>php_mongo.dll</strong>.</p>
  245. <p>Now place this file directly inside your PHP extensions directory located in <code>C:\wamp\bin\php\php5.x\ext\</code>.
  246. If you have this file moved over and the extension line of code added
  247. to your php.ini file then everything should be good to go! Restart your
  248. web server and open up a <code>phpinfo()</code> page to view the results.</p>
  249. <p>You can do a <span class="key">CTRL</span> + <span class="key">F</span> search for mongo and should find details about the module itself.</p>
  250. <h3>Mongo Web Development with PHP</h3>
  251. <p>There is so much to discuss when it comes to web development and
  252. databases. This is only an introduction tutorial so we wont be able to
  253. touch on many topics including users, authentication, updating objects,
  254. multiple databases, etc. But lets finish up by going over the <a href="http://php.net/manual/en/class.mongodb.php">PHP MongoDB class</a> and how we can quickly connect into a database.</p>
  255. <p>Ill use our test DB in this example accessing our previously created
  256. shows collection. We can pull all this data out using PHP and display
  257. the contents on a webpage. Im creating a new PHP file in my local
  258. server root named <strong>shows.php</strong> with the following code:</p>
  259. <div class="dp-highlighter"><div class="bar"><div class="tools"><a href="#" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy to clipboard</a><a href="#" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a></div></div><ol class="dp-c" start="1"><li class="alt"><span><span>&lt;?php&nbsp;&nbsp;</span></span></li><li class=""><span><span class="comment">//&nbsp;Config</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="vars">$dbhost</span><span>&nbsp;=&nbsp;</span><span class="string">'localhost'</span><span>;&nbsp;&nbsp;</span></span></li><li class=""><span><span class="vars">$dbname</span><span>&nbsp;=&nbsp;</span><span class="string">'test'</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span><span class="comment">//&nbsp;Connect&nbsp;to&nbsp;test&nbsp;database</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="vars">$m</span><span>&nbsp;=&nbsp;</span><span class="keyword">new</span><span>&nbsp;Mongo(</span><span class="string">"mongodb://$dbhost"</span><span>);&nbsp;&nbsp;</span></span></li><li class=""><span><span class="vars">$db</span><span>&nbsp;=&nbsp;</span><span class="vars">$m</span><span>-&gt;</span><span class="vars">$dbname</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span><span class="comment">//&nbsp;select&nbsp;the&nbsp;collection</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span><span class="vars">$collection</span><span>&nbsp;=&nbsp;</span><span class="vars">$db</span><span>-&gt;shows;&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;&nbsp;</span></li><li class="alt"><span><span class="comment">//&nbsp;pull&nbsp;a&nbsp;cursor&nbsp;query</span><span>&nbsp;&nbsp;</span></span></li><li class=""><span><span class="vars">$cursor</span><span>&nbsp;=&nbsp;</span><span class="vars">$collection</span><span>-&gt;find();&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span></li><li class=""><span>?&gt;&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;" name="code" class="php">&lt;?php
  260. // Config
  261. $dbhost = 'localhost';
  262. $dbname = 'test';
  263. // Connect to test database
  264. $m = new Mongo("mongodb://$dbhost");
  265. $db = $m-&gt;$dbname;
  266. // select the collection
  267. $collection = $db-&gt;shows;
  268. // pull a cursor query
  269. $cursor = $collection-&gt;find();
  270. ?&gt;
  271. </pre>
  272. <p>What Im doing is selecting our test database and further accessing the internal shows collection. We can run the <a href="http://php.net/manual/en/mongocollection.find.php">find()</a> function on any Mongo collection object to pull out a cursor with all the related internal data.</p>
  273. <p>Now to output this information onto the page lets use <a href="http://php.net/manual/en/function.var-dump.php">var_dump()</a> which is a much better alternative than <a href="http://php.net/manual/en/function.print-r.php">print_r()</a>. Add this last block of code directly underneath the <code>$cursor</code> variable.</p>
  274. <div class="dp-highlighter"><div class="bar"><div class="tools"><a href="#" onclick="dp.sh.Toolbar.Command('ViewSource',this);return false;">view plain</a><a href="#" onclick="dp.sh.Toolbar.Command('CopyToClipboard',this);return false;">copy to clipboard</a><a href="#" onclick="dp.sh.Toolbar.Command('PrintSource',this);return false;">print</a><a href="#" onclick="dp.sh.Toolbar.Command('About',this);return false;">?</a></div></div><ol class="dp-c" start="1"><li class="alt"><span><span class="keyword">foreach</span><span>(</span><span class="vars">$cursor</span><span>&nbsp;</span><span class="keyword">as</span><span>&nbsp;</span><span class="vars">$document</span><span>)&nbsp;{&nbsp;&nbsp;</span></span></li><li class=""><span>&nbsp;var_dump(<span class="vars">$document</span><span>);&nbsp;&nbsp;</span></span></li><li class="alt"><span>}&nbsp;&nbsp;</span></li></ol></div><pre style="display: none;" name="code" class="php">foreach($cursor as $document) {
  275. var_dump($document);
  276. }</pre>
  277. <p

Large files files are truncated, but you can click here to view the full file