PageRenderTime 82ms CodeModel.GetById 3ms app.highlight 64ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  5	<meta property="fb:admins" content="763699465">
  6	<meta property="og:url" content="http://www.hongkiat.com/blog/webdev-with-mongodb-part3/">
  7	<meta property="og:title" content="MongoDB For Beginners: Setting up MongoDB For PHP (Part 3/3)">
  8	<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 »">
  9	<meta property="og:type" content="article">
 10	<meta property="og:image" content="http://media02.hongkiat.com/webdev-with-mongodb-part1/mongodb-logo.jpg">
 11
 12<title>MongoDB For Beginners: Setting up MongoDB For PHP</title>
 13
 14<link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/css.css" rel="stylesheet" type="text/css">
 15<link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/style.css" rel="stylesheet" type="text/css" media="screen, projection">
 16<link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/print.css" rel="stylesheet" type="text/css" media="print">
 17<!--[if IE]><link rel='stylesheet' href="http://static04.hongkiat.com/v5/css/ie.css" type='text/css' media='screen, projection'><![endif]-->
 18
 19<!-- google dfp -->
 20<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>
 21<script type="text/javascript">
 22	GS_googleAddAdSenseService("ca-pub-8918970543424762");
 23	GS_googleEnableAllServices();
 24</script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/google_ads.js"></script>
 25<script type="text/javascript">
 26	GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_145x120-01");
 27	GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_145x120-02");
 28	GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_145x120-03");
 29	GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_sidebar_all_top-right_300x250");
 30</script>
 31<script type="text/javascript">GA_googleFetchAds();</script>
 32<!-- google dfp -->
 33
 34
 35<link rel="alternate" type="application/rss+xml" title="Hongkiat.com RSS Feed" href="http://feeds2.feedburner.com/24thfloor">
 36<link rel="pingback" href="http://www.hongkiat.com/blog/xmlrpc.php">
 37<link rel="shortcut icon" href="http://mediatemplestatic.hongkiat.netdna-cdn.com/logo/hkdc/favicon.ico">
 38
 39
 40<script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/jquery_002.js"></script>
 41<script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/jquery-ui.js"></script>
 42<script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/include-top.js"></script>
 43
 44<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/">
 45<script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/jquery.js"></script>
 46<link rel="prev" title="Cartoonize Your Face With IMadeFace iPhone App" href="http://www.hongkiat.com/blog/cartoonize-face-with-imadeface/">
 47<link rel="next" title="WordPress Job Board Themes And Plugins – Best Of" href="http://www.hongkiat.com/blog/wp-job-board-themes-plugins/">
 48
 49<link rel="canonical" href="http://www.hongkiat.com/blog/webdev-with-mongodb-part3/">
 50<link rel="shortlink" href="http://www.hongkiat.com/blog/?p=16530">
 51	<link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/SyntaxHighlighter.css" type="text/css" rel="stylesheet">
 52	
 53<!--Plugin WP Missed Schedule 2013.1024.8888 Active - Tag 6d807758f47abdb4ae626b9fa261d2f5-->
 54
 55
 56<!-- All in One SEO Pack 2.0.4 by Michael Torbert of Semper Fi Web Design[1034,1123] -->
 57<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">
 58
 59<meta name="keywords" content="web design">
 60
 61<!-- /all in one seo pack -->
 62
 63<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}
 64.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}
 65.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}
 66.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}
 67.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>
 68
 69<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;">
 70                                         Hongkiat is conducting research
 71 to better understand and meet the needs of the users of their site. 
 72Would 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>
 73<a name="top"></a>
 74
 75<!-- stats -->
 76<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>
 77<!-- stats -->
 78
 79<!-- sticky header -->
 80<div style="top: 0px;" id="hSlideContainer">
 81	<div id="hSlideContent">
 82		<ul id="sliderLeft">
 83		
 84			<li class="hkdc_logo"><a href="http://www.hongkiat.com/blog/#top">Back to Home, top</a></li>
 85			
 86						
 87						<li id="hPrevNext">
 88				<div class="prev"><a href="http://www.hongkiat.com/blog/wp-job-board-themes-plugins/" rel="next">prev</a> </div>
 89				<div class="next"><a href="http://www.hongkiat.com/blog/cartoonize-face-with-imadeface/" rel="prev">next</a> </div>
 90			</li>
 91			
 92			<li class="sharetxt">Share this post - </li>
 93			<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>
 94			<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>
 95			<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>
 96			<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>
 97						
 98		</ul>
 99		
100		<ul id="sliderRight">
101			<li class="searchbox">
102				<form id="searchform" method="get" action="/blog/search">
103				<input name="q" id="s" class="search" placeholder="E.g. Free vectors" type="text">
104				</form>			
105			</li>
106			<li class="btt"><a href="#top" title="Back to top"></a></li>
107		</ul>
108	</div>
109</div>	
110<!-- sticky header -->
111
112
113	<!-- header type #1 -->
114	<div id="headerbanner01" class="clearfix">
115		<div class="headerbanner_wrap clearfix">
116				
117				<div class="s728">
118				<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>
119				</div>
120				
121				<div class="s230">
122				<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>
123				</div>
124		
125			
126		</div>
127	</div>
128	<!-- header type #1 -->
129	
130	<!-- header start -->
131	<div id="header" class="clearfix">
132		<div class="logorow clearfix">
133			<div class="thelogo">
134				<h1><a href="http://www.hongkiat.com/blog/">hongkiat.com</a></h1>
135			</div>
136			<div class="thebanner">
137            
138				<!-- BuySellAds Zone Code -->
139                <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>
140                <!-- End BuySellAds Zone Code -->
141			</div>
142		</div>
143		
144		<div class="navirow clearfix">
145			<ul class="sf-menu sf-js-enabled">
146				<li class="home"> <a class="sf-with-ul" href="http://www.hongkiat.com/blog/">Home<span class="sf-sub-indicator"> »</span></a>
147					<ul style="display: none; visibility: hidden;">
148						<li><a href="http://www.hongkiat.com/blog/about-us/">About Us</a></li>
149						<li><a href="http://www.hongkiat.com/blog/advertise/">Advertise</a></li>
150						<li><a href="http://www.hongkiat.com/blog/contact/">Contact us</a></li>
151						<li><a href="http://www.hongkiat.com/blog/write-for-us/">Become an author</a></li>
152						<li><a href="http://www.hongkiat.com/blog/submit-news-tips/">Submit tips</a></li>
153					</ul>
154				</li>
155				<li class=" photoshop"><a href="http://www.hongkiat.com/blog/category/photoshop/">Photoshop</a></li>
156				<li class=" icons"><a href="http://www.hongkiat.com/blog/category/free-icons/">Icons</a></li>
157				<li class="active design"><a href="http://www.hongkiat.com/blog/category/design/">Design</a></li>
158				<li class=" wordpress"><a href="http://www.hongkiat.com/blog/category/wordpress/">WordPress</a></li>
159				<li class=" tools"><a href="http://www.hongkiat.com/blog/category/tools/">Tools</a></li>
160				<li class=" inspiration"><a href="http://www.hongkiat.com/blog/category/inspiration/">Inspiration</a></li>
161				<li class=" graphics"><a href="http://www.hongkiat.com/blog/category/graphics/">Graphics</a></li>
162				<li class=" wallpapers"><a href="http://www.hongkiat.com/blog/category/free-wallpapers/">Wallpapers</a></li>
163				<li class=" howto"><a href="http://www.hongkiat.com/blog/category/how-to/">How-to</a></li>
164				<li class=" web20"><a href="http://www.hongkiat.com/blog/category/web-20/">Web 2.0</a></li>
165                <!--
166				<li class=" freebies"><a href="/blog/category/freebies-online/">Freebies</a></li>
167                -->
168                <li class="deals"><a href="http://hongki.at/deals/">Deals</a></li>
169			</ul>
170			
171			<div class="searchbox">
172				<form id="searchform" method="get" action="/blog/search">
173				<input name="q" id="s" class="search" placeholder="E.g. Free vectors" type="text">
174				</form>
175			</div>
176		</div>
177		
178	</div>
179	<!-- header end -->
180	
181		
182	<div id="main" class="clearfix">
183		<div class="contentwrap"><div class="content single">
184  	<div class="post clearfix" id="post-16530">
185	   	
186		<!-- google_ad_section_start -->
187		<h1>MongoDB For Beginners: Setting up MongoDB For PHP (Part 3/3)</h1>
188		<!-- google_ad_section_end -->
189		
190		<!-- post meta -->
191		<div class="sMeta">
192			<p>
193				By 
194					<strong><a href="http://www.hongkiat.com/blog/author/jake/" title="Posts by Jake Rocheleau" rel="author">Jake Rocheleau</a></strong>. 
195				<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>
196				<span class="edit"></span>
197			</p>  
198		</div>
199		
200		                    <!-- // -->
201                    <div class="gad_wrap"> 
202						<script language="JavaScript"> 
203						var google_adnum = 0;
204						function google_ad_request_done(google_ads) {	
205						var s = ''; var i;
206						if (google_ads.length == 0) { return; }
207							if (google_ads.length == 1) {		
208								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>';
209							}
210							else if (google_ads.length > 1) {	
211								s += '<div class=\"gad_adFeedback\"><a href=\"' + google_info.feedback_url + '\">Ads by Google</a></div>';
212								for(i = 0; i < google_ads.length; ++i) {
213								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>';
214								}
215							}
216							if (google_ads[0].bidtype == "CPC") { 
217								google_adnum = google_adnum + google_ads.length;
218							}	
219						document.write(s);
220						return;
221						}
222						google_ad_client = 'pub-8918970543424762'; 
223						google_ad_channel = '0510687918';
224						google_ad_output = 'js'; 
225						google_max_num_ads = '1';
226						google_ad_type = 'text'; 
227						google_feedback = 'on';
228						google_skip = google_adnum;
229						</script> 
230						<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">India’s 1st Red Bull Flugtag Fly with Indian Physics. Apply now.</span></div>
231					</div>
232                    <!-- /// -->
233                    			
234		<!-- content -->
235		<div class="sContent intxt">
236			<!-- google_ad_section_start -->    
237			<p>Before diving into this, I recommend that you read the following related articles if you have not:</p>
238<ul>
239<li><a href="http://www.hongkiat.com/blog/webdev-with-mongodb-part1/">Introduction to MongoDB</a></li>
240<li><a href="http://www.hongkiat.com/blog/webdev-with-mongodb-part2/">Basic MongoDB shell commands</a></li>
241</ul>
242<p>The MongoDB server is built to already work with your current web 
243server. The problem is that you’ll need to install drivers for your 
244preferred backend language – PHP, Ruby, Node.js, Perl, whatever. I won’t
245 go into the process of installing WAMP/MAMP because this is a bit off 
246topic from Mongo.</p>
247<p class="sw"><img src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/mongodb-logo.jpg" height="282" width="500"></p>
248<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>
249<p><strong>Note:</strong> You can still work with your MongoDB server 
250without a web server. But most applications would require this and 
251that’s why I’m focusing primarily on MongoDB for web development.</p>
252<p>You can get some output from the MongoDB process by visiting the 
253localhost address using your installation’s specific port number.</p>
254<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>
255<p><code>http://localhost:28017</code></p>
256<p>This address should still work properly regardless of your local web server being online or not.</p>
257<p>After you have WAMP or MAMP installed and running you can visit the 
258localhost web server on port :80 to see the default page template.</p>
259<p>Now I’m going to walk you through installing the PHP driver, and we’ll finish up developing over MongoDB’s PHP class library.</p>
260<h3>Setup the MongoDB PHP Drivers</h3>
261<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>
262<p>Here’s the line of code you should run from terminal:</p>
263<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
264sudo pecl install mongo</pre>
265<p>If you already have Pear installed then you don’t need to run the 
266first line. That is only for PHP installs which are not updated to the 
267latest Pear library. But after the commands finish locate your <strong>php.ini</strong> file and add the following bit of code:</p>
268<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
269</pre>
270<p>You should notice a similar block of code somewhere midway down the 
271file which has a slew of other lines mirroring extension=name. Most 
272extensions are commented out but the lines without a hash symbol(#) are 
273currently active extensions.</p>
274<p>After you’ve added this line save &amp; close the file, then restart your Apache web server for the new changes to take effect.</p>
275<h4>Mongo PHP Extension on Windows</h4>
276<p>All users on Windows will also need to edit their php.ini file. This 
277can be accomplished directly from the WAMP context menu by clicking on 
278the icon, then moving to PHP -&gt; php.ini. You’ll need to add the same 
279line of code except the filename should be <strong>php_mongo.dll</strong>. </p>
280<p>Also instead of installing through the command line it’s much easier 
281to download a copy of the extension and move this over manually.</p>
282<p>Windows users should head over to <a href="https://github.com/mongodb/mongo-php-driver/downloads">this Github directory</a>
283 full of MongoDB PHP drivers. Find the latest release which supports 
284your version of PHP (5.2, 5.3, 5.4) and download the .zip. Once you 
285extract the folder find the extension which matches your version of PHP.
286 In my case I’ll use <strong>php_mongo-1.2.12-5.3-vc9.dll</strong> and rename this to <strong>php_mongo.dll</strong>.</p>
287<p>Now place this file directly inside your PHP extensions directory located in <code>C:\wamp\bin\php\php5.x\ext\</code>.
288 If you have this file moved over and the extension line of code added 
289to your php.ini file then everything should be good to go! Restart your 
290web server and open up a <code>phpinfo()</code> page to view the results.</p>
291<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>
292<h3>Mongo Web Development with PHP</h3>
293<p>There is so much to discuss when it comes to web development and 
294databases. This is only an introduction tutorial so we won’t be able to 
295touch on many topics including users, authentication, updating objects, 
296multiple databases, etc. But let’s 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>
297<p>I’ll use our test DB in this example accessing our previously created
298 “shows” collection. We can pull all this data out using PHP and display
299 the contents on a webpage. I’m creating a new PHP file in my local 
300server root named <strong>shows.php</strong> with the following code:</p>
301<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
302// Config
303$dbhost = 'localhost';
304$dbname = 'test';
305
306// Connect to test database
307$m = new Mongo("mongodb://$dbhost");
308$db = $m-&gt;$dbname;
309
310// select the collection
311$collection = $db-&gt;shows;
312
313// pull a cursor query
314$cursor = $collection-&gt;find();
315
316?&gt;
317</pre>
318<p>What I’m 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>
319<p>Now to output this information onto the page let’s 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>
320<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) {
321 var_dump($document);
322}</pre>
323<p

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