这个连接正确吗?

发布于 2024-12-07 18:40:38 字数 377 浏览 0 评论 0原文

我对 MySQL 连接很陌生,我把它放在一起,它正在工作,但我不知道是否有更好的方法来做到这一点?

$q = $dbc -> prepare("SELECT l.layout, a.email 
                      FROM layout AS l 
                      JOIN accounts AS a ON (l.id = a.id) 
                      WHERE email = ?");
$q -> execute(array($_POST['email']));

基本上有 2 张表,一张称为布局,一张称为帐户,我想从布局中选择布局,其中电子邮件与帐户中的 ID 匹配?

I am very new to MySQL joins and I have put this together, it is working but I don't know if there is a better way to do this??

$q = $dbc -> prepare("SELECT l.layout, a.email 
                      FROM layout AS l 
                      JOIN accounts AS a ON (l.id = a.id) 
                      WHERE email = ?");
$q -> execute(array($_POST['email']));

Basically there are 2 tables one called layout and one called accounts, I want to select the layout from layout where the email that matches the id in accounts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白首有我共你 2024-12-14 18:40:38

看来没有更好的办法了。你的很好。唯一的建议是不要使用 AS 关键字作为表别名。该位置的 AS 在 MySQL 中是有效的,但并不常用。它可能不适用于每个 RDBMS,因此最好不要养成使用的习惯。

SELECT l.layout, a.email 
FROM layout l JOIN accounts a ON (l.id = a.id) 
--          ^               ^
-- alias follows table name directly
WHERE email = ?

There doesn't appear to be a better way. Yours is fine. The only suggestion is not to use the AS keyword for table aliases. The AS in that position is valid in MySQL, but just isn't commonly used. It may not be valid in every RDBMS so it may be best to not to get in the habit of using.

SELECT l.layout, a.email 
FROM layout l JOIN accounts a ON (l.id = a.id) 
--          ^               ^
-- alias follows table name directly
WHERE email = ?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文