你好我插入空值有问题。
如果我在phpmyadmin中测试这样效果很好:
INSERT INTO all
(id
,album_id
,album_picture_id
,style_id
,style_picture_id
)VALUES('',175,null,null,null )
但是当我插入Doctrine2时:
$getAlbum = $this->doctrine->em->getRepository('models\Album')->findOneBy(array('id'=>175)); $all = new models\All; $all->setAlbumPicture(NULL); $all->setAlbum($getAlbum); $all->setStyle(NULL); $all->setStylePicture(NULL); $this->doctrine->em->persist($all); $this->doctrine->em->flush();
我收到此错误: [星期六12月14日14:24:36] [错误] [客户端84.255.196.168] PHP致命错误:未捕获异常'PDOException',消息'SQLSTATE [42000]:语法错误或访问冲突:1064您的错误SQL语法;查看与您的MySQL服务器版本对应的手册,以便在'all(album_id,album_picture_id,style_id,style_picture_id)VALUES(175,NULL,'在第1行'/home/hosting/easydrobe.com/data)附近使用正确的语法/application/libraries/Doctrine/DBAL/Statement.php:131\nStack trace:\ n#0 /home/hosting/easydrobe.com/data/application/libraries/Doctrine/DBAL/Statement.php(131):PDOStatement- >执行(NULL)\ n#1 /home/hosting/easydrobe.com/data/application/libraries/Doctrine/ORM/Persisters/BasicEntityPersister.php(239):Doctrine \ DBAL \ Statement-> execute()\ n#2 /home/hosting/easydrobe.com/data/application/libraries/Doctrine/ORM/UnitOfWork.php(896):Doctrine \ ORM \ Persisters \ BasicEntityPersister-> executeInserts()\ n#3 / home / hosting /eydydrobe.com/data/application/libraries/Doctrine/ORM/UnitOfWork.php(304):Doctrine \ ORM \ UnitOfWork-> executeInserts(Object / DocMine / ORM \ Mapping \ ClassM inhome/hosting/easydrobe.com第131行/data/application/libraries/Doctrine/DBAL/Statement.php
我的模特: http://pastebin.com/vgq4eWky
任何想法? 谢谢你的帮助。
答案 0 :(得分:1)
All
是保留关键字。您应该在实体定义中引用它,例如:
/**
* @ORM\Table(name="`all`")
* @ORM\Entity()
*/
class All
{
// ... etc ...
}