php - 博客发布 SQL 连接问题

标签 php mysql sql codeigniter

我目前正在 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/

相关文章:

c# - Linq Entity Framework

PHP fatal error : Uncaught Error: Call to a member function prepare() on null

php - mysql 中的子查询与 php

mysql - 子子查询无法访问在外部范围内定义的表

sql - 使用宽列/稀疏表时需要超过8k记录限制

mysql - 在空 JOIN 值上切换 sql 列

php - 如何在多个网页上显示导航栏?

PHP:插入数据库后打印帖子值

php - 如何在 php 中显示所有行

mysql - 如何从 ORACLE 中的函数中将 1,2,3.... 返回到单独的行中的 N?