CentOS用yum安装 php-pecl-mongo扩展找不到mongo.so

/ 0评 / 0

php5.6-pecl-mongo-1.12 php56-php-pecl-mongo-1.6.14-1.el6.remi.x86_64php 5.6

需要的 mongo.so 下载地址 http://download.csdn.net/download/gl145698789/9433530 (mongodb-php5.6-mongo1.6.12.zip)

http://blog.51yip.com/cache/1447.html

php-pecl-mongo-1.6.12-1.el6.remi.5.6.x86_64.rpm

http://rpms.famillecollet.com/store/php/pecl/mongo/1.6.12/

php 连接mongo 的 测试代码:

<?php
//$conn = new MongoClient("mongodb://admin:admin@localhost2:27017/local");
//$mongo = new Mongo("mongodb://root:123456!@#$%@12.56.24.98:27017/admin");
//$dbs = $mongo->listDBs();
//print_r($dbs);

//$dsn = "mongodb://10.20.15.18:27017/root:123456!@#$%/admin";
//$dsn = "mongodb://root:123456!@#$%@10.20.15.18:27017/admin";
//$mongo = new MongoClient($dsn);

//$mongo = new Mongo('mongodb://10.20.15.18:27017');
//$mongo = new MongoClient("mongodb://root:123456@10.20.15.18:27017/admin");
//$mongo = new MongoClient("mongodb://12.56.24.9:27017", array('username'=>'root','password'=>'123456!@#$%','db'=>'admin'));
$mongo = new MongoClient("mongodb://10.20.15.18:27017", array('username'=>'root','password'=>'123456','db'=>'admin'));
//$dbs = $mongo->listDBs();
//echo '<pre>';
//print_r($dbs);
密码包含 @ 字符,dsn方式汇报错,另外,推荐 MongoClient,不要用 new mongo了

一个小技巧:

$config = array(
'username' => 'root',
'password' => '123456',
'dbname' => 'blog',
'connection_string' => sprintf('mongodb://%s:%d/%s', $hosts, $port,$dbname)
);

try{
if ( !class_exists('Mongo')){
echo ("The MongoDB PECL extension has not been installed or enabled");
return false;
}
$connection = new MongoClient($config[‘connection_string’],array(‘username’=>$config[‘username’],’password’=>$config[‘password’]));
return $this->db = $connection->selectDB($config[‘dbname’]);
}catch(Exception $e) {
return false;
}

网站效率:0.298秒内查询了25次数据库