php连接mongodb
wget 'https://codeload.github.com/mongodb/mongo-php-driver/zip/master' -O /usr/local/src/mong_php.zip
cd /usr/local/src/
unzip mong_php.zip
cd mongo-php-driver-master/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
vi /usr/local/php/etc/php.ini //增加 extension = mongo.so
/usr/local/php/bin/php -m
重启apache,重新加载php
测试:
vi /usr/local/apache2/htdocs/1.php //增加
<?php
// 连接到mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// 选择一个数据库
$db = $m->mydb;
echo "Database mydb selected";
?>
访问 curl localhost/1.php 如果输出
Connection to database successfullyDatabase mydb selected
说明正确。
更多测试访问http://www.runoob.com/mongodb/mongodb-php.html
扩展: mongodb分片 http://www.lanceyan.com/tech/arch/mongodb_shard1.html