如何在PHP Mongodb中使用ANDo逻辑运算符使用MongoDB \ Driver \ Manager类

时间:2017-02-17 11:25:29

标签: php mongodb

如果数据库中存在用户名和密码,我想登录用户。我到目前为止已经完成了

<?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 ];中存在,该行成功过滤数据但是如何确认密码呢?如果我使用用户名获取密码然后比较密码,这不奇怪吗?

0 个答案:

没有答案