我下载了Mongodb - 已安装 - >创建bat文件 - >创建Data / db文件夹 - >在cmd工作正常
然后,从GitHib版本5.3 TS VC6下载PHP驱动程序。
在“xampp / php / ext”中复制了“php_mongo.dll”
然后编辑“xampp / php / php.ini” - extension = php_mongo.dll
重启Apache - 停止并启动
检查
[http:// localhost / xampp /] - > phpinfo() - >显示“mongo”
我运行以下代码并获得ERROR
“致命错误:在第11行的E:\ xampp \ htdocs \ teach \ mongo \ index.php中找不到类'MongoClient'”
一次又一次
请帮忙
测试RUNNING
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>C MongoDB Insert</title>
</head>
<body>
<?php
echo '<pre>';
// Connect to the MongoD with defaults which are localhost and port 27017)
$m = new MongoClient();
echo '<br />Connection var dump below <br />';
var_dump($m);
// Use a DataBase (will be created if it doesn't exist)
echo '<br />database var dump below <br />';
$db = $m->demodb;
var_dump($db);
// Use a Collection (will be created if it doesn't exist)
$coll = $db->democoll;
echo '<br />Collection var dump below <br />';
var_dump($coll);
$coll->insert(array(
'key1' => 'Another Row',
'AnArray' => array(
'embedded array value 1',
'embedded array value 2'
),
'embeddedDoc1' => array(
'embedDoc1Key1' => 'Embedded text in Doc1',
'embedDoc1Key2' => 'More text for fun'
)
));
echo '<h2 style="color:red">Below is our Document</h2>';
$myDoc = $coll->findOne(array('key1' => 'Another Row'));
print_r($myDoc);
echo '</pre>';
?>
</body>
</html>
答案 0 :(得分:1)
升级PHP版本
后,程序的每个部分都是正确的我们至少需要MongoClient的1.3.x PHP驱动程序,但最好将XAMPP升级到PHP 5.4并安装最新的PHP 1.4.x驱动程序。 - 谢谢@stennie