Tampilkan postingan dengan label PHP. Tampilkan semua postingan
Tampilkan postingan dengan label PHP. Tampilkan semua postingan

Minggu, 27 Maret 2011

Using MongoDB and CodeIgniter On Windows


Installing MongoDB


First of all, you need to download MongoDB binary file for windows. You can get these from here. After the download is completed, create a new directory 'C:\data\db'. It is needed as default to store your database. Then, call the command prompt. If you are using Windows 7 as you OS, don't forget to run cmd as administrator. If you don't do this, then the installation won't start.

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

After things with MongoDB are settled, it's time to set MongoDB driver for PHP. Don't worry, this is simple. First, you have to download driver here. Download the correct driver for your environment. At the time this article is created, I downloaded mongo-1.1.4.zip. You will see a lot of file when you extract the file. I'll help you to choose the correct file :
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
For me, I'm using apache with php 5.3 installed. Therefore, I'm using 'mongo-1.1.4-php5.3vc6ts'.
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!

Jumat, 09 April 2010

Uninstall Oracle 10g Secara Manual

Wew, pengalaman dapet proyek PHP-Oracle dimulai dengan pengalaman buruk.. Begini kronologisnya :
Saya menginstall Oracle 10G XE pada Windows XP tapi hang di tengah-tengah proses. Saya mencoba menghapus tapi tidak bisa. Mau install ulang keluar warning :
default database listener port, 5521, currently in use.
Saya coba googling-googling untuk mencari solusi.. Akhirnya ketemu beberapa potong kalimat :
Early versions of the XE installer had various cases where it would do nothing, or would hang, or just exit without messages part way through, so it's possible you've hit one of these.
Kesimpulannya : banyak yang mengalami kejadian seperti saya :|

Usut punya usut, Oracle tidak bisa dihapus karena menyebarkan 'tentakel-tentakel'-nya di banyak registry dan port. Jadi, untuk bisa di-uninstall,, harus dimatikan dulu. Berikut langkah-langkahnya :

1. Stop service Oracle yang sedang berjalan. Klik start->run->services.msc. Stop semua service yang berbau-bau Oracle (namanya dimulai dengan 'Oracle')
2. Jalankan regedit dan hapus(mungkin nama sedikit berbeda, tapi yang jelas hapus yang berbau-bau Oracle) :
HKEY_CURRENT_USER\SOFTWARE\ORACLE
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet Services\EventLog\Application\Oracle.oracle
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet Services\OracleDBConsole
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet Services\Oracle10g_home
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet Services\OraclService
3. Sampai tahap ini, kita sudah bisa menghapus Oracle secara manual di direktori Oracle di-install.

4. Buka c:/windows/assembly dan hapus Oracle.DataAccess serta Polic.Oracle

Simsalabim! Oracle pun terhapus secara sempurna dari Windows XP Anda... Semoga bermanfaat!