In this tutorial I’m going to show you how you can install the Mongo DB extension on php. But first, let me give you a simple introduction on what Mongo DB is. Mongo DB is a NO SQL database, which means Not Only Standard Query Language. Here’s a list of NO SQL databases:
So what’s the advantage of Mongo DB over MySQL or other databases which uses SQL? Here’s the introduction of Mongo DB:
And here’s a summary in case you’re feeling lazy today:
- High Performance
- High availability
- Easy Scalability
- Rich query Language
Well, I’m not that expert at explaining things. And the main purpose of this article is to show you how to install Mongo DB, so I guess a simple outline will do. And yeah, you’re lazy today so you won’t really be reading this part and have gone ahead with the installation.
First, you’ll have to go to the download page of the Mongo DB. And you’ll see a highly confusing table, you’ll really have to examine it carefully in order to download the right one. Basically you’ll want a production release that is for Windows 32-bit operating system. It says Windows 32-bit, but I don’t really know if it works on Windows 95 or the first version of Windows. But if you are on Windows 7 just like me, the it will probably work for you.
Next, download the mongo DB extension for php. You can use this link to download the php extension if you didn’t catch the link above. But first, you need to make sure that we have the same php version and compiler. If not then you can use this link, a collection of mongo DB extensions for php 5.3.5. And if you don’t know how to get the information below, just create a new php file and type phpinfo(), save it then access the file on your browser.
Next, extract the mongo DB archive file. Then go to the bin folder. What you’ll see is a bunch of executable files, but you only have to execute 2 of them. Here’s the order of execution:
You can go ahead and try some commands like:
It’s the equivalent of the insert command in sql.
If you want to verify that it is actually stored in the database, you can try out this command:
Yup!, that’s the equivalent of the select statement in sql.
Ok, enough with that. You can go give yourself a jumpstart by taking up the tutorial in the mongo DB site, just click on the big TRY IT OUT LINK to get started.
Next, paste the mongo DB extension to the ext folder in php. The path to my ext folder looks something like the one below. You can make use of it as a basis.
Next, you have to insert this line on the php.ini file. Of course, you don’t paste it on just anywhere else. You have to paste it where the other extensions are
I have placed mine as the first extension on the list, the one’s with the semi-colon at the beginning are disabled. You can also enable and disable existing extensions from the wampserver tray icon. But because the mongo DB extension doesn’t yet exist, we needed to manually place it on the php.ini file:
After that, save the changes to you php.ini file and restart all services from the wampserver tray icon.
To test if you can already make use of Mongo DB in php, just create a new php file and paste this line:
$conn = new Mongo();
If you don’t get any error, then All Izz Well as Phunsuk Wangdu said(that’s from the movie called 3 idiots, definitely worth watching, very funny and inspiring).
But if you get any errors, here’s what you need to do:
- Make sure that mongo.exe and mongod.exe are running, you can go check it out from the Windows Task Manager.
- Make sure that you have the right mongo DB php extension and that it is enabled.
That’s it for this tutorial! Mongo DB is a good My SQL alternative for small php projects. Next time, were going to make a simple CRUD application using php and mongo DB.