当前位置: 动力学知识库 > 问答 > 编程问答 >

database - Mongodb with php on Windows 7 (32 bit) with apache not working

问题描述:

I am trying to run mongodb code with the following system configuration:

  • Operating System: Windows 7 (32 bit)
  • PHP Version: 5.2.9 Apache
  • Version: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i

    PHP/5.2.9

I am using XAMPP in my system.

What I did to configure mongodb with the xampp is below:

  • I went to https://github.com/mongodb/mongo-php-driver/downloads and download the first link (php_mongo-1.3.2RC1.zip) zip.
  • After unzipping the file I copied php_mongo-1.3.2RC1-5.2-vc9.dll DLL file in xampp/php/ext/ directory in my xampp installed directory
  • Then add extension=php_mongo-1.3.2RC1-5.2-vc9.dll in the php.ini file
  • Restarted xampp server
  • Then I saw the xampp phpinfo() and it is displaying that mongodb is installed. Please follow the image below from my phpinfo() page

  • Now I wrote a sample code for using mongodb as below:

    <?php

    $m = new Mongo();

    $db = $m->learningmongo;

    $people = $db->people;

    ?>

and it is displaying the Fetal error on screen as below:

Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017: Unknown error' in E:\xampp\htdocs\mongo\index.php:3 Stack trace: #0 E:\xampp\htdocs\mongo\index.php(3): Mongo->__construct() #1 {main} thrown in E:\xampp\htdocs\mongo\index.php on line 3

Where I am doing wrong, please guide me. Any code sample and web link would be highly appreciated.

分享给朋友:
您可能感兴趣的文章:
随机阅读: