PHP mongoDB cluster connection string is not workingHow can I prevent SQL injection in PHP?Deleting an element from an array in PHPHow to query MongoDB with “like”?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?mongodb connect using phpReference - What does this error mean in PHP?Why shouldn't I use mysql_* functions in PHP?php failed to connect to mongodb socketUnreachable MongoDB replica set using MAMP

Is "you will become a subject matter expert" code for "you'll be working on your own 100% of the time"?

Output a Super Mario Image

Bit one of the Intel 8080's Flags register

A simple problem about Rule

Make 2019 with single digits

Are space camera sensors usually round, or square?

Write a function that returns an iterable object of all valid points 4-directionally adjacent to (x, y)

How are unbalanced coaxial cables used for broadcasting TV signals without any problems?

How to stabilise the bicycle seatpost and saddle when it is all the way up?

Why is the T-1000 humanoid?

Is there any way to land a rover on the Moon without using any thrusters?

Difference in using Lightning Component <lighting:badge/> and Normal DOM with slds <span class="slds-badge"></span>? Which is Better and Why?

Finding the number of digits of a given integer.

Can I fix my boots by gluing the soles back on?

Can you add polynomial terms to multiple linear regression?

Karazuba Algorithm with arbitrary bases

How does a simple logistic regression model achieve a 92% classification accuracy on MNIST?

Where to disclose a zero day vulnerability

Thematic, genred concepts in Ancient Greek?

In Germany, how can I maximize the impact of my charitable donations?

Why is the Digital 0 not 0V in computer systems?

I was promised a work PC but still awaiting approval 3 months later so using my own laptop - Is it fair to ask employer for laptop insurance?

What's 待ってるから mean?

Can I tap all my opponent's lands while they're casting a spell to negate it?



PHP mongoDB cluster connection string is not working


How can I prevent SQL injection in PHP?Deleting an element from an array in PHPHow to query MongoDB with “like”?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?mongodb connect using phpReference - What does this error mean in PHP?Why shouldn't I use mysql_* functions in PHP?php failed to connect to mongodb socketUnreachable MongoDB replica set using MAMP






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I am trying to connect to mongoDB cluster from PHP using below code



$client = new MongoClient('mongodb+srv://username:password@urlToCluster');


It gives me error as



Uncaught exception 'MongoConnectionException' with message 'MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known' 


Not able to connect using connection string










share|improve this question


























  • The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Also mongodb+srv would not be used for local and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be using mongodb+srv and just mean mongodb:// or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.

    – Neil Lunn
    Mar 28 at 10:39











  • I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB

    – hrishi
    Mar 28 at 10:44











  • Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.

    – Neil Lunn
    Mar 28 at 10:48












  • but using same credentials I can connect from terminal successfully.

    – hrishi
    Mar 28 at 11:51

















0















I am trying to connect to mongoDB cluster from PHP using below code



$client = new MongoClient('mongodb+srv://username:password@urlToCluster');


It gives me error as



Uncaught exception 'MongoConnectionException' with message 'MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known' 


Not able to connect using connection string










share|improve this question


























  • The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Also mongodb+srv would not be used for local and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be using mongodb+srv and just mean mongodb:// or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.

    – Neil Lunn
    Mar 28 at 10:39











  • I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB

    – hrishi
    Mar 28 at 10:44











  • Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.

    – Neil Lunn
    Mar 28 at 10:48












  • but using same credentials I can connect from terminal successfully.

    – hrishi
    Mar 28 at 11:51













0












0








0








I am trying to connect to mongoDB cluster from PHP using below code



$client = new MongoClient('mongodb+srv://username:password@urlToCluster');


It gives me error as



Uncaught exception 'MongoConnectionException' with message 'MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known' 


Not able to connect using connection string










share|improve this question
















I am trying to connect to mongoDB cluster from PHP using below code



$client = new MongoClient('mongodb+srv://username:password@urlToCluster');


It gives me error as



Uncaught exception 'MongoConnectionException' with message 'MongoClient::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known' 


Not able to connect using connection string







php mongodb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 10:44







hrishi

















asked Mar 28 at 10:26









hrishihrishi

5503 gold badges11 silver badges28 bronze badges




5503 gold badges11 silver badges28 bronze badges















  • The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Also mongodb+srv would not be used for local and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be using mongodb+srv and just mean mongodb:// or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.

    – Neil Lunn
    Mar 28 at 10:39











  • I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB

    – hrishi
    Mar 28 at 10:44











  • Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.

    – Neil Lunn
    Mar 28 at 10:48












  • but using same credentials I can connect from terminal successfully.

    – hrishi
    Mar 28 at 11:51

















  • The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Also mongodb+srv would not be used for local and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be using mongodb+srv and just mean mongodb:// or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.

    – Neil Lunn
    Mar 28 at 10:39











  • I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB

    – hrishi
    Mar 28 at 10:44











  • Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.

    – Neil Lunn
    Mar 28 at 10:48












  • but using same credentials I can connect from terminal successfully.

    – hrishi
    Mar 28 at 11:51
















The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Also mongodb+srv would not be used for local and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be using mongodb+srv and just mean mongodb:// or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.

– Neil Lunn
Mar 28 at 10:39





The error means what it says, which is basically your machine where you are running the code cannot resolve the name you are giving it. Also mongodb+srv would not be used for local and not sure what this could possibly have to do with an SSH Tunnel. Chances are unless someone actually set up the DNS records for your server then you either A. Should not be using mongodb+srv and just mean mongodb:// or B. You mean to connect to an Atlas hosted cluster, possibly not reachable by your application host because you never added it to the whitelist of allowed clients.

– Neil Lunn
Mar 28 at 10:39













I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB

– hrishi
Mar 28 at 10:44





I am trying to connect to atlas cluster. It is already there. I am removing reference to SSH from question. It was separate DB

– hrishi
Mar 28 at 10:44













Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.

– Neil Lunn
Mar 28 at 10:48






Then basically your application host cannot see the atlas cluster. As noted, you probably did not add your application host to the whitelist, OR your application host does not have access to touch the Atlas cluster from it's own network rules, or even do DNS lookups in general. Not a programming problem.

– Neil Lunn
Mar 28 at 10:48














but using same credentials I can connect from terminal successfully.

– hrishi
Mar 28 at 11:51





but using same credentials I can connect from terminal successfully.

– hrishi
Mar 28 at 11:51












1 Answer
1






active

oldest

votes


















1
















MongoClient is deprecated long time ago and likely doesn't support new replica set syntax.



https://docs.atlas.mongodb.com/driver-connection/ recommends to use up to date Mongodb driver:



$client = new MongoDBClient('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395284%2fphp-mongodb-cluster-connection-string-is-not-working%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1
















    MongoClient is deprecated long time ago and likely doesn't support new replica set syntax.



    https://docs.atlas.mongodb.com/driver-connection/ recommends to use up to date Mongodb driver:



    $client = new MongoDBClient('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');





    share|improve this answer





























      1
















      MongoClient is deprecated long time ago and likely doesn't support new replica set syntax.



      https://docs.atlas.mongodb.com/driver-connection/ recommends to use up to date Mongodb driver:



      $client = new MongoDBClient('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');





      share|improve this answer



























        1














        1










        1









        MongoClient is deprecated long time ago and likely doesn't support new replica set syntax.



        https://docs.atlas.mongodb.com/driver-connection/ recommends to use up to date Mongodb driver:



        $client = new MongoDBClient('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');





        share|improve this answer













        MongoClient is deprecated long time ago and likely doesn't support new replica set syntax.



        https://docs.atlas.mongodb.com/driver-connection/ recommends to use up to date Mongodb driver:



        $client = new MongoDBClient('mongodb+srv:////username:password@urlToCluster/?ssl=true&authSource=admin');






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 12:45









        Alex BlexAlex Blex

        18.5k2 gold badges24 silver badges52 bronze badges




        18.5k2 gold badges24 silver badges52 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395284%2fphp-mongodb-cluster-connection-string-is-not-working%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현