1. 首先在mongo官网上下载mongodb数据库
http://www.mongodb.org/display/DOCS/Downloads
2. 安装PHP驱动
不同操作系统的安装方法
http://www.mongodb.org/display/DOCS/PHP+Language+Center
在linux下只需要跑下面的命令就安装完成了
sudo pecl install mongo
在php.ini中添加扩展模块,然后查看phpinfo,是否已经启用了mongo扩展。
3. 编写测试脚本
// connect
$m = new Mongo();
// select a database
$db = $m->comedy;
$collection = $db->cartoons;
// add an element
$obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
$collection->insert($obj);
// add another element, with a different "shape"
$obj = array( "title" => "XKCD", "online" => true );
$collection->insert($obj);
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $obj) {
echo $obj["title"] . "\n";
}
// disconnect
$m->close();
运行上面的脚本输出
Calvin and Hobbes
XKCD
就说明你已经成功安装了mongo db和php驱动