0

I just installed MongoDB on my Linux (12.04) with its extension for PHP, and both seems to be well installed (phpinfo() shows infos about MongoDB, enabled etc.).

But when i want to load a page containing the following code, nothing is displayed:

<?php

    $m = new MongoClient();

    echo "Connection to database sucessfull";

    $db=$m->mydb;

    echo "Database mydb selected";

?>

Any suggestion ?

Thanks

mric750
  • 183
  • 8
  • What does the error log says? – mrhn Mar 12 '16 at 09:28
  • The character encoding of the HTML document was not declared – mric750 Mar 12 '16 at 09:31
  • Possible duplicate of [The character encoding of the HTML document was not declared](http://stackoverflow.com/questions/11996257/the-character-encoding-of-the-html-document-was-not-declared) – mrhn Mar 12 '16 at 09:33
  • @MartinHenriksen i already tried this solution, it doesn't solve the problem – mric750 Mar 12 '16 at 09:35
  • I think the problem doesn't come from character encoding because when i echo something before new mongoClient() it works... – mric750 Mar 12 '16 at 09:41
  • do u have driver for mongodb to php connectivity installed their. I faced the same problem on my linux remote server where i managed to find the solution by installing the driver by command pecl install mongo. – Shaggie Mar 12 '16 at 17:08

1 Answers1

0

Actual Syntactic code is this:

    $m = new MongoClient('mongodb://localhost', [
    'username' => 'abc',
    'password' => 'abc@123',
    'db'       => 'abc'
    ]);

May be you try once. Use get_last_error() and dump it on screen and send.

pavanjoshi
  • 240
  • 2
  • 10