【发布时间】:2011-09-27 06:43:42
【问题描述】:
此代码不会根据 ID 搜索找到记录
<?php
$userid = $_GET['id'];
$theObjId = new MongoId($userid);
$connection = new Mongo('localhost');
$db = $connection->test->items;
$item = $db->findOne(array('_id' => $theObjId));
echo 'Item: ' . $item . '<br>';
echo 'UserID: ' . $userid . '<br>';
echo 'TheObjID: ' . $theObjId;
$connection->close();
?>
$userid 由另一个 .php 文件中的表单提供
这是输出 ....
$item: Array
$userid: 4e0dfc8e7bfb8bac12000000
$theObjId: 4e0dfc8e7bfb8bac12000000
输出证明我的变量包含 ID
【问题讨论】: