Created
September 21, 2012 03:36
-
-
Save tbsmcd/3759587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$mongo = new Mongo('127.0.0.1:27017'); // local の場合。ポート 27017 | |
// example が存在しない場合、 CREATE DATABASE 相当の操作は自動でやってくれる | |
$db = $mongo->selectDB('example'); | |
// RDB でいうところの table | |
// test が存在しない場合(以下略) | |
$collection = $db->selectCollection('test'); | |
// お、ドキュメント | |
$document = array( | |
'name' => 'Tomoaki Kanemoto', | |
'age' => 44, | |
'team' => 'Tigers', | |
'hometown' => array( | |
'prefecture' => 'Hiroshima', | |
'city' => 'Hiroshima', | |
), | |
); | |
$collection->insert($document); | |
$object = $collection->findOne(); | |
var_dump($object); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment