Created
December 3, 2015 21:39
-
-
Save samueleresca/d7d4db4d209a86a74a65 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
$host = 'localhost:27017'; | |
$dbname = 'myMongoDb'; | |
$colname = "emp"; | |
try { | |
//Istanzio la connessione all host | |
$conn= new MongoClient($host); | |
//Seleziono il database tramite il $dbname | |
$db=$conn->selectDB($dbname); | |
//Seleziono la connection tramite il $colname | |
$coll=$conn->selectCollection($dbname,$colname); | |
//Effettuo le query di ricerca dei valori | |
//Cerco le row con la field deptno = 20 | |
$cursor=$coll->find(array("deptno"=>20)); | |
$cursor->sort(array("sal"=>1)); | |
foreach ($cursor as $c){ | |
foreach ($c as $key=>$val){ | |
if($key != "_id"){ | |
print "$val t"; | |
} | |
} | |
print "n"; | |
} | |
} catch (Exception $e) { | |
print "exception: n"; | |
die($e->getMessage()."n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment