MongoDB PHP

netz98 new media GmbH

by Christian Münch

Was ist MongoDB?

  • Dokumentenorientert NoSQL Datenbank
  • Kein formales Schema
  • Keine Transaktionen (nur auf Dokumentenbene)
  • Dokumente werden in BSON (Binary JSON) abgelegt
  • humongous => gigantisch

BSON

http://bsonspec.org/#/specification
element	::= "\x01" e_name double	Floating point
          | "\x02" e_name string	UTF-8 string
          | "\x03" e_name document	Embedded document
          | "\x04" e_name document	Array
          | "\x05" e_name binary	Binary data
          | "\x06" e_name	Undefined — Deprecated
          | "\x07" e_name (byte*12)	ObjectId
          | "\x08" e_name "\x00"	Boolean "false"
          | "\x08" e_name "\x01"	Boolean "true"
          | "\x09" e_name int64	UTC datetime
          | "\x0A" e_name	Null value
          | "\x0B" e_name cstring cstring	Regular expression
          | "\x0C" e_name string (byte*12)	DBPointer — Deprecated
          | "\x0D" e_name string	JavaScript code
          | "\x0E" e_name string	Symbol — Deprecated
          | "\x0F" e_name code_w_s	JavaScript code w/ scope
          | "\x10" e_name int32	32-bit Integer
          | "\x11" e_name int64	Timestamp
          | "\x12" e_name int64	64-bit integer
          | "\xFF" e_name	Min key
          | "\x7F" e_name	Max key
                    

Begriffe für SQL Entwickler

  • Connection = Connection
  • Database = Database
  • Table = Collection
  • Row = Document
  • Column = Field
  • Joins = Embedded Document Linking
  • Primary Key = Primary Key
  • Foreign Key = null
  • Aggregation (Group, Sum, ...) = Aggregation Pipeline
  • Store Procedures = Embedded JavaScript Engine (V8)
  • Index = Index
  • Trigger = null

CRUD SQL

  • C - INSERT INTO
  • R - SELECT FROM
  • U - UPDATE SET
  • D - DELETE FROM

CRUD MongoDB

  • C - collection.insert()
  • R - collection.find()
  • U - collection.update()
  • D - collection.remove()

PHP Modul Installation

                        
$> pecl install mongo
...
Build process completed successfully
Installing '/usr/lib/php5/20121212/mongo.so'
install ok: channel://pecl.php.net/mongo-1.4.5
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongo.so" to php.ini
                        
                    

Prüfen ob alles läuft

CLI

                        
php -m | grep mongo
                        
                    

Prüfen ob alles läuft

Webserver

Mongo PHP-Info

Programmierer brauchen eine API

http://api.mongodb.org

http://php.net/mongo

Noch Fragen?

sonst geht's zum Restaurant "Zum güldenen M"