在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.安装mongodb linux下安装mongodb很简单,执行如下命令完成安装 wget http://downloads.mongodb.org/linux/mongodb-linux-i686-2.2.2.tgz cd /usr/local/mongodb/bin
这样mongodb就在端口12345运行了
3.安装mongodb的php驱动扩展 yum install php-pear cd /usr/local/php/bin sudo ./pecl install mongo
安装完成后会出现如下提示 Build process completed successfully Installing '/usr/lib/php/modules/mongo.so' install ok: channel://pecl.php.net/mongo-1.3.4 configuration option "php_ini" is not set to php.ini location You should add "extension=mongo.so" to php.ini
然后编辑php.ini添加 添加extension=mongo.so
4.测试脚本 <?php error_reporting(E_ALL); ini_set('display_errors', '1'); header("Content-type: text/plain"); $connection = new Mongo(127.0.0.1:12345); $db = $connection->mydb; $collection = $db->mycollection; $myobj = array("first_name" => "John", "last_name" => "Doe", "age" => 30); $myobj2 = array("first_name" => "Jane", "last_name" => "Doe", "age" => 27); $collection->insert($myobj); $collection->insert($myobj2); $cursor = $collection->find(); foreach($cursor as $result) { echo "Name: " . $result["last_name"] . ", " . $result["first_name"] . "\n"; echo "Age: " . $result["age"] . "\n\n"; } $db->drop(); $connection->close(); ?> ps:
可能出现的问题: 一: -bash: /usr/local/bin/mongo: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
yum install ld-linux.so.2
二: mongo: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
yum whatprovides libstdc++.so.6 yun install llibstdc++.so.6
|
2022-08-15
2022-08-17
2022-11-06
2022-08-17
2022-07-18
请发表评论