MongoDB远程连接

时间:2015-11-17 13:27:46

标签: php mongodb

我在最后一个版本安装了MongoDB 我想用其他具有此测试代码的服务器连接到MongoDB。 - 在PHP Server中安装了MongoDB驱动程序 - 在MongoDB iptabels中允许使用PHP服务器IP:

PHP代码:



    <?php
$m = new MongoClient("mongodb://X.X.X.X:27017");
$dbname = $m->selectDB("Test");
$collection = $dbname->selectCollection("Shows"); 
$data1 = array(
        'user_id' => 'salam',
        'age' => 20,
        'Status' => 'Allll'
        );
$dbname = $collection->insert($data1, array('$data1' => 1));  
$results = $collection->find();
echo "<pre>";
foreach($results as $test) {
    print_r($test);
} 
echo "</pre>";
?>
&#13;
&#13;
&#13;

ERROR:

  

atal error:未捕获的异常&#39; MongoConnectionException&#39;消息&#39;无法连接到:X.X.X.X.X.X:27017:连接超时&#39;在/home/payam48/domains/.../public_html/includes/classes/class.mongodatabase.php:9堆栈跟踪:#0 /home/payam48/domains/.../public_html/includes/classes/class.mongodatabase .php(9):MongoClient-&gt; __ construct(&#39; mongodb://178.1...')#1 /home/payam48/domains/.../public_html/includes/classes/class。 doctor.php(519):Mongodatabase-&gt; __ construct(&#39; 1c5b98782e44ccd ...&#39;,&#39; b2f202952b685b6 ...&#39;)#2 / home / payam48 / domains / .. ./public_html/includes/classes/class.doctor.php(486):医生 - &gt; online_delete()#3 /home/payam48/domains/.../public_html/application/controllers/managedoctor.php(27):医生 - &gt;删除(&#39; 4&#39;)#4 /home/payam48/domains/.../public_html/application/core/router.class.php(118):managedoctorController-&gt; delete() #5 /home/payam48/domains/.../public_html/index.php(9):router->在/home/payam48/domains/.../public_html/includes/classes/class.mongodatabase.php第9行

0 个答案:

没有答案