php如何使用pecl安装mongodb扩展
前言
本文主要介绍在php中使用pecl安装mongodb扩展的相关内容。以下就不多说了。让我们来看看详细的介绍
环境描述
Php7 centos7 mongodb4.0.5默认情况下,Php不安装mongodb扩展,这会报告类' MongoDB \ driver \ query '未找到错误。
Pecl安装扩展
扩展可以通过pecl轻松安装
注意:如果安装了多个版本的php,则需要对应版本的pecl目录,例如:
在bin pwd/usr/local/PHP 7 . 1/bin binsudo之后。/pecl install MongoDB已安装,在php.ini中添加扩展名=mongodb.so
重新启动php并检查phpinfo
试验
?PHP $ Manager=new MongoDB \ Driver \ Manager(' MongoDB ://localhost :27017 ');//insert data $ bulk=new mong db \ driver \ bulk write;$bulk-insert(['id'=1,' name '=' Google ']);$bulk-insert(['id'=2,' name '=' Github ']);$bulk-insert(['id'=3,' name '=' StackOverFlow ']);$ manager-execute bulk write(' test . sites ',$ bulk);$ filter=[' id '=[' $ gt '=1]];$ options=[' projection '=[' _ id '=0],' sort'=['id'=-1],];//查询数据$ query=new MongoDB \ driver \ query($ filter,$ options);$ cursor=$ manager-execute query(' test . sites ',$ query);foreach($ cursor as $ document){ echo ' pre ';var _ dump($ document);}执行结果:
摘要
以上就是本文的全部内容。希望本文的内容对大家的学习或工作有一定的参考价值。有问题可以留言交流。谢谢你的支持。
版权声明:php如何使用pecl安装mongodb扩展是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。