I am able to login to mongo using the following command:
mongo host_name:port/admin -u 'USERNAME' -p 'PASSWORD'
For PHP I tried below code to connect to mongo:
try{
$m = new MongoClient("mongodb://USERNAME:PASSWORD#host_name:27017");
echo "Connection to database successfully";
}
catch(Exception $ex)
{
echo '<pre>'; print_r($ex->getMessage());
}
But it is not connecting. Gives following error:
Failed to connect to: 10.7.0.225:27017: Authentication failed on database 'admin' with username 'USERNAME': auth failed
I have already created user root with role as root.
Any help would be appreciable. Thanks!
Related
So I have this code and I'm trying to catch an error when I can't connect for some reason (wrong credentials or no network connection or something similar), but it is not working and my app crashes with error.
try {
$connection = new Remote([
'host' => $equipment->ip_address,
'port' => 22,
'username' => EquipmentAccess::where('equipment_id', $equipment->id)->first()->ssh_user,
'password' => EquipmentAccess::where('equipment_id', $equipment->id)->first()->ssh_password,
]);
$command = $request->command . ' ' . $request->argv;
$ip = $connection->exec($command);
} catch (Exception $e) {
echo "Houston, we have a problem:" . $e;
}
If anyone can give me any information about what I missed, it will be highly appreciated.
EDIT: I guess, I wasn't clear enough. It crashes with typical laravel pipeline error and the latest is, that it can't connect to that device. And it should just give me my error message.
EDIT2: here is a link to a SS of the stack-trace - https://gyazo.com/9095d5600be2b7f07ca59d93624f9187
I am trying to connect my RDS to my phalcon app. I have settings in my security group that allows access to the database from my server and from localhost. Here is some of my code from my index.php file
$config = new Phalcon\Config\Adapter\Ini("../config/config.ini");
$di->set('db', function() use ($config){
try {
$db = new \Phalcon\Db\Adapter\Pdo\Mysql(array(
"host" => $config->development->host,
"username" => $config->development->username,
"password" => $config->development->password,
"dbname" => $config->development->dbname
));
} catch (Exception $e) {
die("<b>Error when initializing database connection:</b> " . $e->getMessage());
}
return $db;
});
Then I try a call to my database in one of my controllers here:
public function indexAction()
{
$users = Users::find();
echo "There are ", count($users), "\n";
}
When I run that controller the page times out and throws this error:
Error when initializing database connection: SQLSTATE[HY000] [2002] Operation timed out
The data in the config file is correct. I am able to connect to it just fine via the terminal. What am I doing wrong? Any thoughts/suggestions/insights? Thanks
I installed mongo 3.0.0 on my ubuntu server.
I tried to use PHP (with appropriate lib installed) to connect to mongo to learn sth new. Unfortunaltey I cannot go any further.
My user configuration looks like this:
> use testdb
switched to db testdb
> show users
{
"_id" : "testdb.testdb",
"user" : "testdb",
"db" : "testdb",
"roles" : [
{
"role" : "readWrite",
"db" : "testdb"
}
]
}
Then I try to execute the following PHP code:
try{
$uri = "mongodb://testdb:password#xxx.xxx.xxx.xxx:27017/testdb";
$options = array("connectTimeoutMS" => 30000);
$client = new MongoClient($uri, $options );
}
catch(Exception $e) {
echo 'Message: ' .$e->getMessage();
die();
}
$db = $client->selectDB("testdb");
I get "Message: Failed to connect to: xxx.xxx.xxx.xxx:27017: Authentication failed on database 'testdb' with username 'testdb': auth failed".
In /etc/mongod.conf I have "auth = true" uncommented
I also verified the conncetion with:
> nc -w 3 -v xxx.xxx.xxx.xxx 27017 Connection to xxx.xxx.xxx.xxx 27017
> port [tcp/*] succeeded!
I dig through Internet, i spent few hours already on this, I even re-installed mongo and set everything up again without any success.
Could you point to where to look for solution?
The authentication schema of 3.0 is not compatible with 2.x drivers. One way you should be able to make it work is by downgrading the authentication mechanism:
use "admin"
var schema = db.system.version.findOne({"_id" : "authSchema"})
schema.currentVersion = 3
db.system.version.save(schema)
Then create a user and you should be able to connect with it.
When I try to connect my parse cloud it shows an error
the username XYZ already taken
I have tried this code:
public function setUp() {
$this->parseUser = new parseUser;
$this->testUser = array(
'username' => 'XYZ',
'password' => '*******',
'email' => 'abc#mail.com',
'customField' => 'customValue'
);
}
my parseconfig.php file look like this
class parseConfig {
const APPID = 'kS131sdje....';
const MASTERKEY = 'w1d...';
const RESTKEY = 'o16r...';
const PARSEURL = 'https://api.parse.com/1/';
}
Can you help me? Is it trying to SignUp instead of Signin?
I downloaded this code from the link below and am trying to connect it to my Parse.com cloud
https://github.com/apotropaic/parse.com-php-library
You should check out the Parse documentation for PHP for user operations.
Here are two examples for signup and signin:
Registration:
$user = new ParseUser();
$user->set("username", "my name");
$user->set("password", "my pass");
$user->set("email", "email#example.com");
// other fields can be set just like with ParseObject
$user->set("phone", "415-392-0202");
try {
$user->signUp();
// Hooray! Let them use the app now.
} catch (ParseException $ex) {
// Show the error message somewhere and let the user try again.
echo "Error: " . $ex->getCode() . " " . $ex->getMessage();
}
Login:
try {
$user = ParseUser::logIn("myname", "mypass");
// Do stuff after successful login.
} catch (ParseException $error) {
// The login failed. Check error to see why.
}
I am attempting to connect to a database in an instance on Google cloud sql but it is telling me access is denied.
Im just wondering am I missing something here...
I have requested an IP and inserted that into the authorized networks
I have created a database and set a user using SQL prompt (found in original view of Google APIs Console) and granted all privileges to that user for that database.
I have listed the users in that database to make sure "adrian" exists and that I have done that correctly.
I have insured the app being used to connect is authorized in the access control
I have set a root password in the access control section.
Here is my app.yaml file...
application: guestbookadrian12
version: 1
runtime: php
api_version: 1
handlers:
- url: .*
script: main.php
env_variables:
DEVELOPMENT_DB_HOST: ''
DEVELOPMENT_DB_USERNAME: 'root'
DEVELOPMENT_DB_PASSWORD: 'password'
DEVELOPMENT_DB_NAME: 'guestbookadrian12'
PRODUCTION_CLOUD_SQL_INSTANCE: '/cloudsql/guestbookadrian12:my-cloudsql-instance'
PRODUCTION_DB_USERNAME: 'adrian'
PRODUCTION_DB_PASSWORD: 'password'
PRODUCTION_DB_NAME: 'guestbookadrian12'
Here is some php code where it creates the connection...
if (strpos(getenv('SERVER_SOFTWARE'), 'Development') === false) {
$conn = mysqli_connect(null,
getenv('PRODUCTION_DB_USERNAME'),
getenv('PRODUCTION_DB_PASSWORD'),
null,
null,
getenv('PRODUCTION_CLOUD_SQL_INSTANCE'));
$db = getenv('PRODUCTION_DB_NAME');
//echo 'Database = : '.$db;
} else {
$conn = mysqli_connect(getenv('DEVELOPMENT_DB_HOST'),
getenv('DEVELOPMENT_DB_USERNAME'),
getenv('DEVELOPMENT_DB_PASSWORD'));
$db = getenv('DEVELOPMENT_DB_NAME');
}
if ($conn->connect_error) {
die("Could not connect to database: $conn->connect_error " .
"[$conn->connect_errno]");
}
if ($conn->query("CREATE DATABASE IF NOT EXISTS $db") === FALSE) {
die("Could not create database: $conn->error [$conn->errno]");
}
The error Im getting is
Could not create database: Access denied for user 'adrian'#'localhost' to database 'guestbookadrian12' [1044]
Thank you