Is there a way to get the output of "rs.status();" from the php driver?
Passing the following setting to the Command function of the MongoDB Driver
array('replSetGetStatus'=>1)
Results in an error message:
Array
(
[0] => access denied; use admin db
[1] => 0
)
You can reuse the same connection; you just have to get the admin db from the object:
$connection->admin->command(array("replSetGetStatus"=>1)
If you haven't already, you'll need to create a database connection object to the 'admin' db so that you can then call the output of rs.status() through the driver as you specified.
mongodb://[username:password#]host1[:port1][,host2[:port2:],...]/db
See the docs here
Related
I'm currently writing an app in PHP that connects to a MongoDB database.
I've managed to successfully authenticate a user with the dbAdmin role in the MongoDB Database that I've setup, and I've created a user "TestUser" with no roles that I want to get information about while authenticated as the dbAdmin User. however I can't figure out how to run the "db.getUser()" command from PHP.
My understanding is that I should be able to use the "MongoDB::command()" method to run any actual mongoDB commands directly, however, the following code...
$mongo = new MongoClient("localhost:27017");
$mongoDb = $mongo->{'test'}
$mongoDb->authenticate($username, $password); //This returns a successful response of array('ok' => 1)
print_r($mongoDb->command(array("getUser" => "TestUser")));
Generates this response: -
(
[ok] => 0
[errmsg] => no such command: getUser
[code] => 59
[bad cmd] => stdClass Object
(
[getUser] => TestUser
)
)
The "getUser" is a command of a Database in MongoDB though, right? If so, why am I getting this response, and how do I construct a correct statement to be able to get information about a User from MongoDB in PHP?
I looked into this more, by fetching a list of all possible methods available to the database by using...
$mongoDb->command(array("listCommands" => 1));
This informed me that "getUser" apparently is not an existing command. I'm not sure why not, I guess it's because it's a User Management command and not a typical Database Command.
At any rate, "usersInfo" is a command that is available. By doing the following...
$mongoDb->command(array("usersInfo" => array("user" => $username, "db" => $database)));
I was able to get the data about the user that I wanted, so I guess that answers my question. Hopefully this helps anyone else whose encountering the same problem trying to setup their PHP app with MongoDb.
I am using jorgebg/yii-eoauth library. I use the library with Yii EAuth extension. By requirements yii eauth
Requirements
Yii 1.1 or above
PHP curl extension
loid extension
EOAuth extension
Well, I come across with this problem. I checked it in local with linkedin account (no social accounts work on local server, except linkedin ) and it works perfectly. But login system doesn't work on server. Can you help me in this case ? Thanks in advance !
I didn't write my code here, because I thought, the problem doesn't depend on my code. If it is not, I can put here necessary code.
EDIT:
Error was :
Argument 1 passed to EOAuthUtils::GetAccessToken() must be an instance of
OAuthConsumer, instance of __PHP_Incomplete_Class given, called in
protected/extensions/eoauth/EOAuthUserIdentity.php on line 138 and defined
In line 138 of EOAuthUserIdentity.php was written:
// Upgrade to access token.
$token = EOAuthUtils::GetAccessToken($consumer, $token, $oauthVerifier,
$this->provider->access_token_endpoint);
I put logger pre($consumer,1); before above code. and I had in local:
OAuthConsumer Object
(
[key] => 7........k
[secret] => s........r
[callback_url] =>
)
I had on server:
__PHP_Incomplete_Class Object
(
[__PHP_Incomplete_Class_Name] => OAuthConsumer
[key] => 7.........k
[secret] => s........r
[callback_url] =>
)
the same php version on local and server
You need load class before unserialize object. If u don't do this, object unserialize to __PHP_Incomplete_Class.
see PHP problem with "__php_incomplete_class"
I'm refactoring an existing application which is using old methods to connect and interact with a mysql database like mysql_connect() and mysql_fetch_array which had code like:
Update
The only output Im getting on the page is the below, which are empty arrays.
Array ( [initial] => Array ( ) [additional] => Array ( ) )
Final update This was an issue with the root user not having access to %. I was getting an error like: The user specified as a definer ('root'#'%') does not exist on output this is fixed by running the command:
grant all on *.* to 'root'#'%' identified by 'password' with grant option;
The reason for converting was using the originally coded use of mysql_connect() (not by me) does not work (as far as I know) with mysql when you have remote connections turned off (which I do).
Why isn't my new code outputting anything? The original code above works in development env. where remote connections is turned off, but not in production.
Thank you.
Your class has a missing closing bracket } at the end.
You do not select database
Why do you create $this->dbConn everywhere, you defined it in your constructor.
Where is your $this->dbConn->query defined? $this->dbConn is a resource of connection.
NOTE
Add error_reporting(E_ALL); and ini_set('display_errors', 1); to catch your errors.
Using the example from the manual:
$mongo = new Mongo("mongodb://sf2.example.com,ny1.example.com", array("replicaSet" => "myReplSet"));
When I check $mongo, it says it is indeed connected. I thought I could then call $mongo->isMaster() to get replica set details, but that doesn't work. Is that not a proper way of doing this?
isMaster isn't a PHP function (see http://www.php.net/manual/en/class.mongo.php for a list of functions available in the Mongo class). You can do:
$result = $mongo->myDb->command(array("isMaster" => 1));
This runs the isMaster command on the myDb database (it doesn't matter what db you run it on).
I'm getting a weird error when running through the tutorial in the e-book, "Practical CakePHP Projects" in chapter 8, "A Cake Control Panel". Everything is built out, the DB is set-up and completely blank, and I'm running through the test at the end of the chapter to verify everything is working... I'm not sure what happened, but I keep running into the following error:
Warning (512): DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:
Aro: Array
(
[User] => Array
(
[id] => 2
[username] => admin
[group_id] => 1
[created] => 2010-07-05 12:07:45
[modified] => 2010-07-05 12:08:00
)
)
It looks like it's telling me that there is no node in my Aro that is identified by the model 'User' with the id of '2'. But looking at my Aros table, I can clearly see that the last record is the following:
id:4, parent_id:2, model:User, foreign_key:2, alias:User:2, lft:2, rght:3
And the following relative record is my users table:
id:2, username:admin, password:hashed, group_id:1, created:date, modified:date
Where am I going wrong? Any direction someone could point me in would be greatly appreciated.
Thanks!
If you've setup the ACLExtras Automated tool to sync ACOs, Execute the following command in the CakePHP console:
./Console/cake AclExtras.AclExtras aco_sync
It seems for me that you either do not have corresponding record in acos table or permission in acos_aros. If that is the case you will need to add $this->Auth->allow('*'); in beforeFilter() in you app_controller.php and after that add ACO(s) and allow it to admin user.
I would advice you to follow official tutorial Simple Acl controlled Application because the information in the book becomes outdated. Something may not work with CakePHP 1.3.