如果数据库中存在用户名和密码,我想登录用户。我到目前为止已经完成了
<?php
try {
$name = 'john';
$password = 12345;
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$filter = [ 'name' => $name ];
$query = new MongoDB\Driver\Query($filter);
$res = $manager->executeQuery("DBName.Col", $query);
$data = current($res->toArray());
if (!empty($data)) {
} else {
echo 0;
}
} catch (MongoDB\Driver\Exception\Exception $e) {
$filename = basename(__FILE__);
echo "The $filename script has experienced an error.\n";
echo "It failed with the following exception:\n";
echo "Exception:", $e->getMessage(), "\n";
echo "In file:", $e->getFile(), "\n";
echo "On line:", $e->getLine(), "\n";
}
?>
如果数据库$filter = [ 'name' => $name ];
中存在,该行成功过滤数据但是如何确认密码呢?如果我使用用户名获取密码然后比较密码,这不奇怪吗?