jcramalho

Inserção dum registo em MongoDB

Jan 12th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <?php
  2.   try
  3.     {
  4.       $m = new Mongo(); // connect
  5.       $db = $m->selectDB("local");
  6.     }
  7.   catch ( MongoConnectionException $e )
  8.     {
  9.       echo '<p>Couldn\'t connect to mongodb, is the "mongo" process running?</p>';
  10.       exit();
  11.     }
  12.    
  13.   $db->users->insert( array( pnome => $_REQUEST['pnome'],
  14.                          unome => $_REQUEST['unome'],
  15.                          sexo => $_REQUEST['sexo'],
  16.                          hacademicas => $_REQUEST['hacademicas']) );
  17.                          
  18.   $collection = new MongoCollection($db, 'users');
  19.  
  20.   $cursor = $collection->find();
  21.  
  22.   foreach ($cursor as $doc)
  23.   {
  24.     echo "<pre>";
  25.     var_dump($doc);
  26.     echo "</pre>";
  27.   }
  28. ?>
Advertisement
Add Comment
Please, Sign In to add comment