So, I have this simple login function that tries to match the email address with the password in the database and compare it with the data entered by the user through the form.
function login($email, $password){
$m = new Mongo("localhost");
$m->connect();
$db = $m->users;
$collection = $db->test_collection;
echo "<pre>";
var_dump($collection->findOne(array('name' => 'john')));
var_dump($collection->find(array('name' => 'john')));
echo "</pre>";
}
I do not understand why find () returns a cursor object. The answers?
This is a mongo document
array(5) {
["_id"]=>
object(MongoId)#22 (1) {
["$id"]=>"4d7eaa848baf84d32b000000"
}
["activated"]=> (true)
["email"]=> "john@smith.com"
["name"]=> "john"
["password"]=> "334c4a4c42fdb79d7ebc3e73b517e6f8"
}
How would I make a βWHEREβ query that could find both email and password in the same document? I obviously do not get paramates correctly for find () and findOne () queries. What is the correct syntax in PHP?
source
share