zoukankan      html  css  js  c++  java
  • 【转】ubuntu 下安装mongodb php 拓展的方法

    按照上面的方法安装成功之后,写一个 mongodb 的php测试脚本,用来测试是否可以 正确连接上mongodb ,并查询结果。

    参考: http://php.net/manual/en/class.mongodb-driver-query.php

    参考: https://dba.stackexchange.com/questions/112386/whats-the-procedure-to-set-up-username-password-on-mongodb

    <?php
    $mongo = new MongoDBDriverManager('mongodb://joe:asdf@127.0.0.1:27017/test');
    
    $id           = new MongoDBBSONObjectId("5a914df2f69030dd45832355");
    $filter      = ['_id' => $id];
    //$filter      = [];
    $options = []; 
    
    $query = new MongoDBDriverQuery($filter, $options);
    $rows   = $mongo->executeQuery('test.mycollection', $query); 
    //var_dump($rows);
    foreach ($rows as $document) {
      var_dump($document);
    

      

    --------------------------------------------------------------------------------------------------------------------------

    linux下mongodb php驱动安装

    linux下使用php开发mongodb程序,需要安装php驱动,安装步骤如下:

    注:
    笔者(habadog1203)php的版本:5.2.10
    php目录:/home/work/php5210/

    (1)去github下载mongo-php-driver
    地址是:https://github.com/mongodb/mongo-php-driver
    笔者下载的版本是:mongodb-mongo-php-driver-1.2.2-23-g820dd82.tar.gz

    (2)解压到php的ext目录下
    笔者解压路径是:/home/work/php5210/ext/mongodb-mongo-php-driver-820dd82

    (3)到解压路径下执行phpize
    命令为:
    cd /home/work/php5210/ext/mongodb-mongo-php-driver-820dd82
    /home/work/php5210/bin/phpize
    目的是生成configure文件,请务必确认configure文件的生成

    (4)安装mongo.so
    命令为:
    cd /home/work/php5210/ext/mongodb-mongo-php-driver-820dd82
    ./configure
    make
    make install
    目的是生成mongo.so,请务必确认mongo.so的生成
    笔者的extensions目录为:/home/work/php5210/lib/php/extensions/no-debug-non-zts-20060613/
    其下正确生成了mongo.so

    (5)修改php.ini,添加mongo.so的扩展
    在php.ini里加入以下配置
    extension=mongo.so

    大功告成,可写程序测试与mongodb的交互了。

    注意点:
    (1)执行phpize需要系统安装autoconf,否则会提示”Cannot find autoconf”,症状为:
    Configuring for:
    PHP Api Version: 20041225
    Zend Module Api No: 20060613
    Zend Extension Api No: 220060519
    Cannot find autoconf. Please check your autoconf installation and the
    $PHP_AUTOCONF environment variable. Then, rerun this script.

    解决方案为:安装autoconf
    用root账号执行以下命令即可:
    yum -y install autoconf

    以上命令共安装两个软件包
    imake-1.0.2-3.i386.rpm
    autoconf-2.59-12.noarch.rpm

    当然,不用yum的话,也可以手动安装,命令为
    cd /usr/src
    wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
    tar -zvxf m4-1.4.9.tar.gz
    cd m4-1.4.9/
    ./configure && make && make install
    cd ../
    wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
    tar -zvxf autoconf-2.62.tar.gz
    cd autoconf-2.62/
    ./configure && make && make install

    (2)安装完autoconf后,phpize执行完能生成configure文件,执行./configure时,可能会报以下错误:
    configure: error: Cannot find php-config. Please use –with-php-config=PATH
    因为找不到php-config(例如,php是别处编译生成,拷贝到本地的)
    加入–with-php-config参数即可,如下:
    ./configure –with-php-config=/home/work/php5210/bin/php-config

    (3)以上步骤参见于php官网:
    http://www.php.net/manual/en/mongo.installation.php

  • 相关阅读:
    第十五章:字段与属性
    第二十章:封装与继承
    第二十一章;泛型List
    第十九章:对象初始化器
    第十八章:构造方式
    第十七章:方法的重载
    request和response对象常用方法
    面向对象(1)
    request和response
    tomcat
  • 原文地址:https://www.cnblogs.com/oxspirt/p/8471705.html
Copyright © 2011-2022 走看看