Sekilas
PHP + mongoDB
Hadi Ariawan
@hadiariawan
[email protected]
http://hadiariawan.web.id
* Download mongoDB di http://
www.mongodb.org/downloads pilih versi dan
mongoDB yang sesuai dengan platform yang
anda gunakan.
* Penulis menggunakan mongoDB versi 1.6.5 di
Windows 32 bit
*Instalasi (1)
* Unzip mongodb-win32-i386-1.6.5 di (misal) D:\
rename jadi mongodb (convenience reason)
* Lalu create direktori untuk lokasi data (secara
default tidak di-create oleh mongoDB). Misal
D:\mongodb-data\db
* Struktur Direktori :
* D:\mongodb
* D:\mongodb-data\db
*Instalasi (2)
* Buka command prompt (di windows)
* Buka direktori d:\mongodb\bin
* Execute mongo.exe dan sesuaikan option
dbpath
* > mongo –-dbpath=d:\mongodb-data\db
*Running mongoDB (1)
* Contoh Screenshot
*Running mongoDB (2)
* Dua hal yang dibutuhkan untuk
mengkoneksikan php dan mongoDB :
* 1. mongoDB server
* 2. install PHP Driver
Untuk pengguna windows download driver di
http://github.com/mongodb/mongo-php-driver/d
ownloads
*PHP + mongoDB (1)
*Unzip PHP driver, copy file php_mongo.dll kedalam direktori
extension PHP (biasanya di php\ext)
*Tambahkan baris berikut ini di file php.ini (di bagian
extension)
* extension=php_mongo.dll
*Restart web server
*Periksa phpinfo() untuk memastikan extension mongoDB telah
di load oleh PHP
*PHP + mongoDB (2)
* Mongo::__construct ([ string $server =
"mongodb://localhost:27017" [, array $options
= array("connect" => TRUE) ]] )
*Code : Connection
* Mongo::__construct ([ string $server =
"mongodb://localhost:27017" [, array $options
= array("connect" => TRUE) ]] )
*Code : Select Database
* public MongoCollection
MongoDB::createCollection ( string $name [,
bool $capped = FALSE [, int $size = 0 [, int
$max = 0 ]]] )
*Code : Create Collection
* public MongoCollection
MongoDB::selectCollection ( string $name )
*Code : Select Collection
* public mixed MongoCollection::insert ( array
$a [, array $options = array() ] )
*Code : Insert Record
* public MongoCursor MongoCollection::find ([ array
$query = array() [, array $fields = array() ]] )
* public int MongoCollection::count ([ array $query =
array() [, int $limit = 0 [, int $skip = 0 ]]] )
*Code : Query
* public bool MongoCollection::update ( array
$criteria , array $newobj [, array $options =
array() ] )
*Code : Update
* public mixed MongoCollection::remove
([ array $criteria = array() [, array $options =
array() ]] )
*Code : Remove
* MongoDB supports two-dimensional geospatial
indexes. It is designed with location-based queries
in mind, such as "find me the closest N items to my
location." It can also efficiently filter on additional
criteria, such as "find me the closest N museums to
my location."
* Example :
*Geospatial Indexing
* public bool MongoCollection::ensureIndex
( array $keys [, array $options ] )
*Code : Query NEAR
*http://
www.mongodb.org/display/DOCS/PHP+Libraries%2C+F
rameworks%2C+and+Tools
* CakePHP
* CodeIgniter
* Doctrine
* Drupal
* Kohana
* Lithium
* Zend Framework
* etc
* PHP Libraries, Frameworks
and Tools
Hadi Ariawan
@hadiariawan
[email protected]http://hadiariawan.web.id
*Terima Kasih