这个连接正确吗?
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来没有更好的办法了。你的很好。唯一的建议是不要使用
AS
关键字作为表别名。该位置的AS
在 MySQL 中是有效的,但并不常用。它可能不适用于每个 RDBMS,因此最好不要养成使用的习惯。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. TheAS
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.