Connect xampp to MongoDB
Posted
by Jhonny D. Cano -Leftware-
on Stack Overflow
See other posts from Stack Overflow
or by Jhonny D. Cano -Leftware-
Published on 2010-03-12T20:54:06Z
Indexed on
2010/03/12
20:57 UTC
Read the original article
Hit count: 372
Hello
I have a xampp 1.7.3 instance running and a MongoDB 1.2.4 server on the same machine.
I want to connect them, so I basically have been following this tutorial on php.net, it seems to connect but the cursors are always empty. I don't know what am I missing.
Here is the code I am trying. The cursor->valid always says false. thanks
<?php
$m = new Mongo(); // connect
try {
$m->connect();
} catch (MongoConnectionException $ex) {
echo $ex;
}
echo "conecta...";
$dbs = $m->listDBs();
if ($dbs == NULL) {
echo $m->lastError();
return;
}
foreach($dbs as $db) {
echo $db;
}
$db = $m->selectDB("CDO");
echo "elige bd...";
$col = $db->selectCollection("rep_consulta");
echo "elige col...";
$rangeQuery = array('id' => array( '$gt' => 100));
$col->insert(array('id' => 456745764, 'nombre' => 'cosa'));
$cursor = $col->find()->limit(10);
echo "buscando...";
var_dump($cursor);
var_dump($cursor->valid());
if ($cursor == NULL) echo 'cursor null';
while($cursor->hasNext()) {
$item = $cursor->current();
echo "en while...";
echo $item["nombre"].'...';
}
?>
doing this by command line works perfect
use CDO
db.rep_consulta.find()
-- lot of data here
© Stack Overflow or respective owner