I am testing the mongoDB in localhost and successfully installed the mongoDB in localhost. I have tried to connect the mongoDB using PHP in localhost.
It throws the error like 'Authentication failed'. It is successfully authenticated in cmd prompt.
Below is my code:
$username = 'testUser';
$password = 'testPassword';
$m = new MongoClient("mongodb://testUser:testPassword#localhost", array("db" => "testdb"));
Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017: No connection could be made because the target machine actively refused it. ' in E:\xampp\htdocs\xampp\test.php:3 Stack trace: #0 E:\xampp\htdocs\xampp\test.php(3): MongoClient->__construct('localhost:27017', Array) #1 {main} thrown in E:\xampp\htdocs\xampp\test.php on line 3
I have also changed the localhost to ip(127.0.0.1) address but no use. Thanks in advance
Related
im new using mongodb,im trying to connect using php based on tutorial, im using ubuntu 20, i read mongodb default doesnt have user password and only accept 127.0.0.1. this script runs in same server as mongodb
<?php
require("vendor/autoload.php");
$client = new MongoDB\Client(
'mongodb+srv://127.0.0.1/test?w=majority'
);
$db = $client->test;
returns :
PHP Fatal error: Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Failed to parse URI options: Failed to look up SRV record "_mongodb._tcp.127.0.0.1": The specified host is unknown. in /opt/wira/test_mongodb/vendor/mongodb/mongodb/src/Client.php:126
Stack trace:
#0 /opt/wira/test_mongodb/vendor/mongodb/mongodb/src/Client.php(126): MongoDB\Driver\Manager->__construct()
#1 /opt/wira/test_mongodb/test.php(5): MongoDB\Client->__construct()
#2 {main}
thrown in /opt/wira/test_mongodb/vendor/mongodb/mongodb/src/Client.php on line 126
i want online connection with MongoDB cloud in PHP
same source file working properly when i run on localhost in my laptop with empty $server string while i use mongoDb server cloud then i face an error
<?php
session_start();
// $server="";
$server='mongodb+srv://mongo_user_1:<password>#mongodb01-dolny.mongodb.net/test?retryWrites=true&w=majority';
$mongo = new MongoClient($server);
$db=$mongo->blogPosting;
$admin_cl=$db->admin;
$category_cl=$db->category;
$blog_cl=$db->blog;
$contact_cl=$db->contact;
$blog_comment_cl=$db->blog_comment;
?>
Fatal error: Uncaught exception 'MongoConnectionException' with
message '- Found unknown connection string option 'retryWrites' with
value 'true'' in G:\xampp\htdocs\mongo_blog\mongoDb.php:5 Stack trace:
0 G:\xampp\htdocs\mongo_blog\mongoDb.php(5): MongoClient->__construct('mongodb+srv://m...') #1
G:\xampp\htdocs\mongo_blog\blog\index.php(1):
include('G:\xampp\htdocs...') #2 {main} thrown in
G:\xampp\htdocs\mongo_blog\mongoDb.php on line 5
I imported the proper mongodb.dll file in php/ext and also configured php.ini but it seems that I can't connect to mongodb via my php code. Example
<?php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
?>
Fatal error: Uncaught Error: Class 'MongoClient' not found in C:\xampp\htdocs\date\include\db2.php:3 Stack trace: #0 {main} thrown in C:\xampp\htdocs\date\include\db2.php on line 3
I am trying to connect to MongoDB from local (a Azure VM). I can connect when I try in my localhost workspace with the URL of the VM. But, when I try to connect in localhost there is a error:
At localhost:
$m = new Mongo("mongodb://xxx.cloudapp.net:27017");
At local VM:
$m = new Mongo("mongodb://localhost:27017");
I also try with: 127.0.0.1 and xxx.cloudapp.net.
This is the error:
Fatal error: Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017: Permission denied' in /var/www/html/test.php:8 Stack trace: #0 /var/www/html/test.php(8): Mongo->__construct('mongodb://local...') #1 {main} thrown in /var/www/html/test.php on line 8
This is not a new issue. This is a regular issue, the problem is with the instalation.
Please check it out: http://www.php.net/manual/en/mongo.installation.php#mongo.installation.fedora
You have to run
$ /usr/sbin/setsebool -P httpd_can_network_connect 1 and then restart apache service to fix the problem.
Thank you all
i have big problem while connection to a remote informix database server.
here's the code
$db = new PDO("informix:host=192.168.*.*; service=1565;
database=daten; server=name; protocol=onsoctcp;
EnableScrollableCursors=1", "informix", "info00");
print "Connection Established!\n\n";
echo "Table contents: $rows.\n";
I receive the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE=HY000, SQLDriverConnect: -917 [Informix][Informix ODBC Driver][Informix]Must close current database before using a new database.' in /var/www/informix.php:9 Stack trace: #0 /var/www/informix.php(9): PDO->__construct('informix:host=1...', 'informix', 'info00') #1 {main} thrown in /var/www/informix.php on line 9
How can I fix this?
I think you should also set the DB_LOCALE environment variable.
When the client application requests a connection, it sends information, including the DB_LOCALE to the database server.