user.php的;
LikePage.php;
LikeArticle.php;
namespace Acme\DemoBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="like_article") */ class LikePage extends Like { /** * @ORM\Column(type="integer") */ protected $itemid; /** * @ORM\ManyToOne(targetEntity="Article", inversedBy="likes") * @ORM\JoinColumn(name="itemid", referencedColumnName="id") */ protected $article;我以这种方式向数据库添加数据.我正在尝试从Page Entity中检索数据.但是,执行此时;
$likes = $page->getLikes(); foreach($likes as $like) { }我收到这个错误;
An exception occurred while executing 'SELECT t0.id AS id1, t0.userid AS userid2, t0.itemid AS itemid3, t0.userid AS userid4, t0.itemid AS itemid5, t0.itemtype FROM like t0 WHERE t0.itemid = ? AND t0.itemtype IN ('1')' with params [1]: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'like t0 WHERE t0.itemid = '1' AND t0.itemtype IN ('1')' at line 1在这种情况下,我该怎么办?为什么找不到itemid?
喜欢是一个保留字,逃避它或更好地改变你的表名.
文件
将其更改为
* @ORM\Table(name="`like`")