dongya2030 2015-12-29 10:29
浏览 84
已采纳

PDO查询使用具有单独参数的两个表

I have two tables. One with login information logins which holds password column and one with emails emails which holds email column and loginID column. I would like to use parameters on both tables. I would like to find row in emails where email=? and then take the corresponding login id inside that row and match this to a row in logins table. I would then like to match the password to the row in logins. A double separated where statement from two tables.

Something along the lines of:

$prepareTables=$listersDatabase->prepare("select*from emails where email=? left join logins on emails.loginID=logins.ID where password=?");
$prepareTables->execute(array("email@email.com","password123"));

Any help is appriciated

  • 写回答

1条回答 默认 最新

  • dongmaopan5738 2015-12-29 10:43
    关注

    Try this:

    SELECT * 
    FROM
        emails 
    INNER JOIN logins 
    ON emails.loginID=logins.ID 
    WHERE 
        emails.email=?
    AND
        password=?
    

    I used INNER JOIN instead of LEFT JOIN as you have this table inside a WHERE condition anyway. You must put all your conditions inside one WHERE clause.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?