我目前正在 CI(CodeIgniter 框架)中编写博客。我有两张 table :
- Blog_Post 表
- Blog_Banners 表
关系是一个 Blog_Post 有多个 Blog_Banner。
我正在尝试使用以下方法检索特定博客文章的所有博客横幅:
SELECT *
FROM 'blog_posts'
INNER JOIN 'blog_banners'
ON 'blog_posts.id' = 'blog_banners.blog_post_id'
WHERE 'blog_posts.id' = '3'
我不断收到此消息:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''posts' INNER JOIN 'banners' ON 'posts.id' = 'banners.post_id' WHERE 'posts.id'' at line 2
有人会碰巧看到这个错误吗?我在这件事上陷入了相当长的一段时间。
最佳答案
不要对表/列名称使用引号,而使用反引号。另外,整数不应该被引用:
SELECT *
FROM `blog_posts`
INNER JOIN `blog_banners`
ON `blog_posts`.`id` = `blog_banners`.`blog_post_id`
WHERE `blog_posts`.`id` = 3
但是由于没有保留字,你也可以不用反引号就可以了
关于php - 博客发布 SQL 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20489015/