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

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

我有两张桌子。 一个包含 logins code>的登录信息,其中包含密码 code>列,另一个包含电子邮件电子邮件 code>,其中包含 email code>列和 loginID code>列。 我想在两个表上使用参数。 我想在电子邮件中找到行 strong>,其中email =? 然后在该行中获取相应的登录ID,并将其与登录 strong>表中的行匹配。 然后我想将密码与登录 strong>中的行匹配。 一个双重分隔的来自两个表的 em>语句 em>。 p>

以下内容: p>

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

任何帮助都是appriciated p> div>

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.