/Downloads/attachments/MongoDB For Beginners_ Setting up MongoDB For PHP_1.html
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
- <!DOCTYPE html>
- <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">
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta property="fb:admins" content="763699465">
- <meta property="og:url" content="http://www.hongkiat.com/blog/webdev-with-mongodb-part3/">
- <meta property="og:title" content="MongoDB For Beginners: Setting up MongoDB For PHP (Part 3/3)">
- <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 »">
- <meta property="og:type" content="article">
- <meta property="og:image" content="http://media02.hongkiat.com/webdev-with-mongodb-part1/mongodb-logo.jpg">
- <title>MongoDB For Beginners: Setting up MongoDB For PHP</title>
- <link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/css.css" rel="stylesheet" type="text/css">
- <link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/style.css" rel="stylesheet" type="text/css" media="screen, projection">
- <link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/print.css" rel="stylesheet" type="text/css" media="print">
- <!--[if IE]><link rel='stylesheet' href="http://static04.hongkiat.com/v5/css/ie.css" type='text/css' media='screen, projection'><![endif]-->
- <!-- google dfp -->
- <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>
- <script type="text/javascript">
- GS_googleAddAdSenseService("ca-pub-8918970543424762");
- GS_googleEnableAllServices();
- </script><script src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/google_ads.js"></script>
- <script type="text/javascript">
- GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_145x120-01");
- GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_145x120-02");
- GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_145x120-03");
- GA_googleAddSlot("ca-pub-8918970543424762", "hkdc_sidebar_all_top-right_300x250");
- </script>
- <script type="text/javascript">GA_googleFetchAds();</script>
- <!-- google dfp -->
- <link rel="alternate" type="application/rss+xml" title="Hongkiat.com RSS Feed" href="http://feeds2.feedburner.com/24thfloor">
- <link rel="pingback" href="http://www.hongkiat.com/blog/xmlrpc.php">
- <link rel="shortcut icon" href="http://mediatemplestatic.hongkiat.netdna-cdn.com/logo/hkdc/favicon.ico">
- <script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/jquery_002.js"></script>
- <script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/jquery-ui.js"></script>
- <script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/include-top.js"></script>
- <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/">
- <script type="text/javascript" src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/jquery.js"></script>
- <link rel="prev" title="Cartoonize Your Face With IMadeFace iPhone App" href="http://www.hongkiat.com/blog/cartoonize-face-with-imadeface/">
- <link rel="next" title="WordPress Job Board Themes And Plugins – Best Of" href="http://www.hongkiat.com/blog/wp-job-board-themes-plugins/">
- <link rel="canonical" href="http://www.hongkiat.com/blog/webdev-with-mongodb-part3/">
- <link rel="shortlink" href="http://www.hongkiat.com/blog/?p=16530">
- <link href="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/SyntaxHighlighter.css" type="text/css" rel="stylesheet">
-
- <!--Plugin WP Missed Schedule 2013.1024.8888 Active - Tag 6d807758f47abdb4ae626b9fa261d2f5-->
- <!-- All in One SEO Pack 2.0.4 by Michael Torbert of Semper Fi Web Design[1034,1123] -->
- <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">
- <meta name="keywords" content="web design">
- <!-- /all in one seo pack -->
- <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}
- .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}
- .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}
- .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}
- .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>
- <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;">
- Hongkiat is conducting research
- to better understand and meet the needs of the users of their site.
- 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>
- <a name="top"></a>
- <!-- stats -->
- <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>
- <!-- stats -->
- <!-- sticky header -->
- <div style="top: 0px;" id="hSlideContainer">
- <div id="hSlideContent">
- <ul id="sliderLeft">
-
- <li class="hkdc_logo"><a href="http://www.hongkiat.com/blog/#top">Back to Home, top</a></li>
-
-
- <li id="hPrevNext">
- <div class="prev"><a href="http://www.hongkiat.com/blog/wp-job-board-themes-plugins/" rel="next">prev</a> </div>
- <div class="next"><a href="http://www.hongkiat.com/blog/cartoonize-face-with-imadeface/" rel="prev">next</a> </div>
- </li>
-
- <li class="sharetxt">Share this post - </li>
- <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>
- <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>
- <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>
- <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>
-
- </ul>
-
- <ul id="sliderRight">
- <li class="searchbox">
- <form id="searchform" method="get" action="/blog/search">
- <input name="q" id="s" class="search" placeholder="E.g. Free vectors" type="text">
- </form>
- </li>
- <li class="btt"><a href="#top" title="Back to top">↑</a></li>
- </ul>
- </div>
- </div>
- <!-- sticky header -->
- <!-- header type #1 -->
- <div id="headerbanner01" class="clearfix">
- <div class="headerbanner_wrap clearfix">
-
- <div class="s728">
- <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:"<html><body style='background:transparent'></body></html>"" 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:"<html><body style='background:transparent'></body></html>"" 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>
- </div>
-
- <div class="s230">
- <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>
- </div>
-
-
- </div>
- </div>
- <!-- header type #1 -->
-
- <!-- header start -->
- <div id="header" class="clearfix">
- <div class="logorow clearfix">
- <div class="thelogo">
- <h1><a href="http://www.hongkiat.com/blog/">hongkiat.com</a></h1>
- </div>
- <div class="thebanner">
-
- <!-- BuySellAds Zone Code -->
- <div id="bsap_1235460" class="bsap_1235460 bsap"><a href="http://stats.buysellads.com/click.go?z=1235460&b=4754618&g=&s=&sw=1366&sh=768&br=firefox,29,linux&r=0.3205651984819403&link=http://imcreator.com/?utm_source=hongkiat&utm_medium=banner&utm_content=space" onmouseover="window.status = 'http://imcreator.com/?utm_source=hongkiat&utm_medium=banner&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>
- <!-- End BuySellAds Zone Code -->
- </div>
- </div>
-
- <div class="navirow clearfix">
- <ul class="sf-menu sf-js-enabled">
- <li class="home"> <a class="sf-with-ul" href="http://www.hongkiat.com/blog/">Home<span class="sf-sub-indicator"> »</span></a>
- <ul style="display: none; visibility: hidden;">
- <li><a href="http://www.hongkiat.com/blog/about-us/">About Us</a></li>
- <li><a href="http://www.hongkiat.com/blog/advertise/">Advertise</a></li>
- <li><a href="http://www.hongkiat.com/blog/contact/">Contact us</a></li>
- <li><a href="http://www.hongkiat.com/blog/write-for-us/">Become an author</a></li>
- <li><a href="http://www.hongkiat.com/blog/submit-news-tips/">Submit tips</a></li>
- </ul>
- </li>
- <li class=" photoshop"><a href="http://www.hongkiat.com/blog/category/photoshop/">Photoshop</a></li>
- <li class=" icons"><a href="http://www.hongkiat.com/blog/category/free-icons/">Icons</a></li>
- <li class="active design"><a href="http://www.hongkiat.com/blog/category/design/">Design</a></li>
- <li class=" wordpress"><a href="http://www.hongkiat.com/blog/category/wordpress/">WordPress</a></li>
- <li class=" tools"><a href="http://www.hongkiat.com/blog/category/tools/">Tools</a></li>
- <li class=" inspiration"><a href="http://www.hongkiat.com/blog/category/inspiration/">Inspiration</a></li>
- <li class=" graphics"><a href="http://www.hongkiat.com/blog/category/graphics/">Graphics</a></li>
- <li class=" wallpapers"><a href="http://www.hongkiat.com/blog/category/free-wallpapers/">Wallpapers</a></li>
- <li class=" howto"><a href="http://www.hongkiat.com/blog/category/how-to/">How-to</a></li>
- <li class=" web20"><a href="http://www.hongkiat.com/blog/category/web-20/">Web 2.0</a></li>
- <!--
- <li class=" freebies"><a href="/blog/category/freebies-online/">Freebies</a></li>
- -->
- <li class="deals"><a href="http://hongki.at/deals/">Deals</a></li>
- </ul>
-
- <div class="searchbox">
- <form id="searchform" method="get" action="/blog/search">
- <input name="q" id="s" class="search" placeholder="E.g. Free vectors" type="text">
- </form>
- </div>
- </div>
-
- </div>
- <!-- header end -->
-
-
- <div id="main" class="clearfix">
- <div class="contentwrap"><div class="content single">
- <div class="post clearfix" id="post-16530">
-
- <!-- google_ad_section_start -->
- <h1>MongoDB For Beginners: Setting up MongoDB For PHP (Part 3/3)</h1>
- <!-- google_ad_section_end -->
-
- <!-- post meta -->
- <div class="sMeta">
- <p>
- By
- <strong><a href="http://www.hongkiat.com/blog/author/jake/" title="Posts by Jake Rocheleau" rel="author">Jake Rocheleau</a></strong>.
- <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>
- <span class="edit"></span>
- </p>
- </div>
-
- <!-- // -->
- <div class="gad_wrap">
- <script language="JavaScript">
- var google_adnum = 0;
- function google_ad_request_done(google_ads) {
- var s = ''; var i;
- if (google_ads.length == 0) { return; }
- if (google_ads.length == 1) {
- 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>';
- }
- else if (google_ads.length > 1) {
- s += '<div class=\"gad_adFeedback\"><a href=\"' + google_info.feedback_url + '\">Ads by Google</a></div>';
- for(i = 0; i < google_ads.length; ++i) {
- 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>';
- }
- }
- if (google_ads[0].bidtype == "CPC") {
- google_adnum = google_adnum + google_ads.length;
- }
- document.write(s);
- return;
- }
- google_ad_client = 'pub-8918970543424762';
- google_ad_channel = '0510687918';
- google_ad_output = 'js';
- google_max_num_ads = '1';
- google_ad_type = 'text';
- google_feedback = 'on';
- google_skip = google_adnum;
- </script>
- <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&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&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&ai=C88sSoQOYU6qALZCoigbppIDIA_X2rNIGveGc6KABnaP61QUQASDr-ZQDUIi82ZD7_____wFg5Zrpg-AOyAEBqQKUHx84NSNSPqgDAaoEhgFP0IVZWvt6nPEf0XXSBoYUBuhsF1buqnFwx3RHUQufIjaeJQj5eIfatRSichVmik2cErvkJeq3fdEDa2e5BWrP72VxLtjvt7QU7nTrOx9XUOiT0CjiQfmUIHG8fkMtY8Tnqjy_kpSltadz1jVWBcAh13xr7y84Qd5XdYCVCeOfAOkZmB781YAHjYXGOQ&num=1&sig=AOD64_1O7PwxpDFu8Np5tUv1WaR1TDI6yA&client=ca-pub-8918970543424762&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&ai=C88sSoQOYU6qALZCoigbppIDIA_X2rNIGveGc6KABnaP61QUQASDr-ZQDUIi82ZD7_____wFg5Zrpg-AOyAEBqQKUHx84NSNSPqgDAaoEhgFP0IVZWvt6nPEf0XXSBoYUBuhsF1buqnFwx3RHUQufIjaeJQj5eIfatRSichVmik2cErvkJeq3fdEDa2e5BWrP72VxLtjvt7QU7nTrOx9XUOiT0CjiQfmUIHG8fkMtY8Tnqjy_kpSltadz1jVWBcAh13xr7y84Qd5XdYCVCeOfAOkZmB781YAHjYXGOQ&num=1&sig=AOD64_1O7PwxpDFu8Np5tUv1WaR1TDI6yA&client=ca-pub-8918970543424762&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>
- </div>
- <!-- /// -->
-
- <!-- content -->
- <div class="sContent intxt">
- <!-- google_ad_section_start -->
- <p>Before diving into this, I recommend that you read the following related articles if you have not:</p>
- <ul>
- <li><a href="http://www.hongkiat.com/blog/webdev-with-mongodb-part1/">Introduction to MongoDB</a></li>
- <li><a href="http://www.hongkiat.com/blog/webdev-with-mongodb-part2/">Basic MongoDB shell commands</a></li>
- </ul>
- <p>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 language – PHP, Ruby, Node.js, Perl, whatever. I won’t
- go into the process of installing WAMP/MAMP because this is a bit off
- topic from Mongo.</p>
- <p class="sw"><img src="MongoDB%20For%20Beginners:%20Setting%20up%20MongoDB%20For%20PHP_files/mongodb-logo.jpg" height="282" width="500"></p>
- <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>
- <p><strong>Note:</strong> You can still work with your MongoDB server
- without a web server. But most applications would require this and
- that’s why I’m focusing primarily on MongoDB for web development.</p>
- <p>You can get some output from the MongoDB process by visiting the
- localhost address using your installation’s specific port number.</p>
- <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>
- <p><code>http://localhost:28017</code></p>
- <p>This address should still work properly regardless of your local web server being online or not.</p>
- <p>After you have WAMP or MAMP installed and running you can visit the
- localhost web server on port :80 to see the default page template.</p>
- <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>
- <h3>Setup the MongoDB PHP Drivers</h3>
- <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>
- <p>Here’s the line of code you should run from terminal:</p>
- <div class="dp-highlighter"><ol class="dp-c" start="1"><li class="alt"><span><span>sudo apt-get install php5-dev php5-cli php-pear </span></span></li><li class=""><span>sudo pecl install mongo </span></li></ol></div><pre style="display: none;" name="code" class="php">sudo apt-get install php5-dev php5-cli php-pear
- sudo pecl install mongo</pre>
- <p>If you already have Pear installed then you don’t need to run the
- first line. That is only for PHP installs which are not updated to the
- latest Pear library. But after the commands finish locate your <strong>php.ini</strong> file and add the following bit of code:</p>
- <div class="dp-highlighter"><ol class="dp-c" start="1"><li class="alt"><span><span>extension=mongo.so </span></span></li></ol></div><pre style="display: none;" name="code" class="php">extension=mongo.so
- </pre>
- <p>You should notice a similar block of code somewhere midway down the
- file which has a slew of other lines mirroring extension=name. Most
- extensions are commented out but the lines without a hash symbol(#) are
- currently active extensions.</p>
- <p>After you’ve added this line save & close the file, then restart your Apache web server for the new changes to take effect.</p>
- <h4>Mongo PHP Extension on Windows</h4>
- <p>All users on Windows will also need to edit their php.ini file. This
- can be accomplished directly from the WAMP context menu by clicking on
- the icon, then moving to PHP -> php.ini. You’ll need to add the same
- line of code except the filename should be <strong>php_mongo.dll</strong>. </p>
- <p>Also instead of installing through the command line it’s much easier
- to download a copy of the extension and move this over manually.</p>
- <p>Windows users should head over to <a href="https://github.com/mongodb/mongo-php-driver/downloads">this Github directory</a>
- full of MongoDB PHP drivers. Find the latest release which supports
- your version of PHP (5.2, 5.3, 5.4) and download the .zip. Once you
- extract the folder find the extension which matches your version of PHP.
- 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>
- <p>Now place this file directly inside your PHP extensions directory located in <code>C:\wamp\bin\php\php5.x\ext\</code>.
- If you have this file moved over and the extension line of code added
- to your php.ini file then everything should be good to go! Restart your
- web server and open up a <code>phpinfo()</code> page to view the results.</p>
- <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>
- <h3>Mongo Web Development with PHP</h3>
- <p>There is so much to discuss when it comes to web development and
- databases. This is only an introduction tutorial so we won’t be able to
- touch on many topics including users, authentication, updating objects,
- multiple 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>
- <p>I’ll use our test DB in this example accessing our previously created
- “shows” collection. We can pull all this data out using PHP and display
- the contents on a webpage. I’m creating a new PHP file in my local
- server root named <strong>shows.php</strong> with the following code:</p>
- <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><?php </span></span></li><li class=""><span><span class="comment">// Config</span><span> </span></span></li><li class="alt"><span><span class="vars">$dbhost</span><span> = </span><span class="string">'localhost'</span><span>; </span></span></li><li class=""><span><span class="vars">$dbname</span><span> = </span><span class="string">'test'</span><span>; </span></span></li><li class="alt"><span> </span></li><li class=""><span><span class="comment">// Connect to test database</span><span> </span></span></li><li class="alt"><span><span class="vars">$m</span><span> = </span><span class="keyword">new</span><span> Mongo(</span><span class="string">"mongodb://$dbhost"</span><span>); </span></span></li><li class=""><span><span class="vars">$db</span><span> = </span><span class="vars">$m</span><span>-></span><span class="vars">$dbname</span><span>; </span></span></li><li class="alt"><span> </span></li><li class=""><span><span class="comment">// select the collection</span><span> </span></span></li><li class="alt"><span><span class="vars">$collection</span><span> = </span><span class="vars">$db</span><span>->shows; </span></span></li><li class=""><span> </span></li><li class="alt"><span><span class="comment">// pull a cursor query</span><span> </span></span></li><li class=""><span><span class="vars">$cursor</span><span> = </span><span class="vars">$collection</span><span>->find(); </span></span></li><li class="alt"><span> </span></li><li class=""><span>?> </span></li></ol></div><pre style="display: none;" name="code" class="php"><?php
- // Config
- $dbhost = 'localhost';
- $dbname = 'test';
- // Connect to test database
- $m = new Mongo("mongodb://$dbhost");
- $db = $m->$dbname;
- // select the collection
- $collection = $db->shows;
- // pull a cursor query
- $cursor = $collection->find();
- ?>
- </pre>
- <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>
- <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>
- <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> </span><span class="keyword">as</span><span> </span><span class="vars">$document</span><span>) { </span></span></li><li class=""><span> var_dump(<span class="vars">$document</span><span>); </span></span></li><li class="alt"><span>} </span></li></ol></div><pre style="display: none;" name="code" class="php">foreach($cursor as $document) {
- var_dump($document);
- }</pre>
- <p…
Large files files are truncated, but you can click here to view the full file