Installing MongoDB
Type command "fullpath_to_your_mongod.exe_file --install --logpath path_to_log". For example, I have all extracted files on D:\data\installer\mongodb\, so I type "D:\data\installer\mongodb\bin\mongod --install --logpath C:\data\log". I used 'C:\data' directory for the logpath and 'log' as the file name.
At this point, you have successfully installed mongoDB on your machine. Now, you need to get it started. Get the service start by typing 'net start "MongoDB"'. Or alternatively, you can just start the service from services.msc. Find Mongo DB and start the service.
Congratulations ! You have properly installed MongoDB on your computer. To test the database, you can run mongoDB client. Run from command prompt "D:\data\installer\mongodb\mongo". This time, it's okay if you don't run command prompt as administrator. Test any mongodb command there. Here you can get references for MongoDB shell command.
Setting PHP driver
1. VC6 is for Apache (VC9 is for IIS)
2. Thread safe(ts) is for running PHP as an Apache module, non thread safe is for CGI
Simply copy 'php_mongo.dll' to your 'xampp/php/ext' directory and add 'extension=php_mongo.dll' to your php.ini file. Restart the server and there you go.
Test MongoDB with CodeIgniter
Now, let's take a look on how using MongoDB with CodeIgniter. First, create a controller file and add these lines to your controller's constructor :
// Connect to Mongo
$connection = new Mongo('localhost:27017');
// Select a database
$db = $connection->db_name;
// Select a collection
$books = $db->books;
Now, your controller file should look like this :
class Test extends Controller {
function __construct()
{
parent::Controller();
// Connect to Mongo
$connection = new Mongo('localhost:27017');
// Select a database
$db = $connection->db_name;
// Select a collection
$books = $db->books;
}
function index()
{
}
}
Now, save the file and type 'http://servername/index.php/test' on your browser.
If you see nothing, then it works !
Congratulations ! I'll add more on updating data on my other post.
Enjoy, and thank you guys!