I’m trying out PHP driver for the first time that connects to a replica set. Tried 2 different methods first is running the script via the CLI (result is successful), and second, accessing via the web but when accessing it via web and it is throwing a
No suitable servers found ( serverSelectionTryOnce
set): [connection error calling hello on ‘[server1]:[port]’] [connection error calling hello on ‘[server2]:[port]’] [connection error calling hello on ‘[server3]:[port]’]
here is the sample code:
<?php
require “vendor/autoload.php”;
$username = “test”;
$password = ‘password’;
//$stime = microtime(true);
try{
$mongo = new MongoDB\Client("mongodb://${username}:${password}@server1:61972,server2:61972,server3:61972/?replicaSet=mongogsavers0&authSource=stg_db", array("tls" => true, "tlsCAFile" => '/path/certificate/mongosertificate.crt', "tlsCertificateKeyFile" => '/path/certificate/pemfile.pem'));
$form_data = array();
$doc_no = "sample search value";
$collection = $mongo->stg_db->img_stg->find(array("doc_no"=> $doc_no));
foreach ($cursor as $document) {
$image_string = new MongoDB\BSON\Binary($document['img_str'], MongoDB\BSON\Binary::TYPE_GENERIC);
$image_type = $document['type'];
array_push($form_data, array('type' => $image_type));//, 'image_str' => "data:image/jpeg;base64,".$image_string->getData()));
}
echo '<pre>'; print_r($form_data); echo '</pre>';
} catch(MongoDB\Driver\Exception\Exception $e){
echo '<pre>'; print_r($e->getMessage()); echo '</pre>';
}
Here’s the output of the above code via web:
No suitable servers found ( serverSelectionTryOnce
set): [connection error calling hello on ‘[server1]:[port]’] [connection error calling hello on ‘[server2]:[port]’] [connection error calling hello on ‘[server3]:[port]’]
When trying via CLI:
MongoDB 4.2 Php 7.2 mongo PHP driver 1.9
badly need help, thanks in advance.