note 101972 added to class.mongodb
| From: | jeromakay at yahoo dot com | Date: | Thu, 20 Jan 2011 20:19:22 +0000 |
| Subject: | note 101972 added to class.mongodb | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175951@lists.php.net to get a copy of this message | ||
based on what I've read and then applied, you don't have to specifically create a database
or table, you just initialize it.
Indeed, files are not being written inside /data/db, but they will the first moment you start adding
data.
So, I'm taking as an example Twitter, with no db defined, I'm still going to have the db
available if I run this code:
<?php
define('TWITTER_API_VERSION', 1);
date_default_timezone_set("Europe/Dublin");
try
{
$m = new Mongo(); // connect
$db = $m->selectDB("example");
}
catch ( MongoConnectionException $e )
{
echo '<p>Couldn\'t connect to mongodb, is the "mongo" process
running?</p>';
exit();
}
$updates = file_get_contents( "http://api.twitter.com/". TWITTER_API_VERSION
."/statuses/public_timeline.json" );
$updates = json_decode( $updates );
if ( $updates && is_array( $updates ) && count( $updates ) )
{
foreach ( $updates as $update )
{
$db->users->insert( $update );
}
}
?>
Hope this was helpful!
Good luck!
Vladimir Ghetau
----
Server IP: 69.147.83.197
Probable Submitter: 86.45.141.99
----
Manual Page -- http://www.php.net/manual/en/class.mongodb.php
Edit -- https://master.php.net/note/edit/101972
Del: integrated -- https://master.php.net/note/delete/101972/integrated
Del: useless -- https://master.php.net/note/delete/101972/useless
Del: bad code -- https://master.php.net/note/delete/101972/bad+code
Del: spam -- https://master.php.net/note/delete/101972/spam
Del: non-english -- https://master.php.net/note/delete/101972/non-english
Del: in docs -- https://master.php.net/note/delete/101972/in+docs
Del: other reasons-- https://master.php.net/note/delete/101972
Reject -- https://master.php.net/note/reject/101972
Search -- https://master.php.net/manage/user-notes.php