简体   繁体   中英

Error executing sql query Symfony2

I have a problem with my insert into query symfony2, see this picture : http://snapplr.com/snap/yt84

When i try to create a new gallery entity (Upload a picture file on my server), i get this error,

but when i try to update a entity that i've added manual in my database, it's work.

Here is my Entity

 <?php namespace Core\\PageBundle\\Entity; use Doctrine\\ORM\\Mapping as ORM; use Knp\\DoctrineBehaviors\\Model as ORMBehaviors; use Symfony\\Component\\Validator\\Constraints as Assert; /** * media * * @ORM\\Table(name="page_gallery") * @ORM\\Entity(repositoryClass="Core\\PageBundle\\Repository\\GalleryRepository") * @ORM\\HasLifecycleCallbacks */ class Gallery { use ORMBehaviors\\Translatable\\Translatable; public function __call($method, $arguments) { return \\Symfony\\Component\\PropertyAccess\\PropertyAccess::createPropertyAccessor()->getValue($this->translate(), $method); } /** * @var integer * * @ORM\\Column(name="id", type="integer") * @ORM\\Id * @ORM\\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\\Column(type="string", length=255, nullable=true) */ private $path; /** * @Assert\\Image(maxSize="3096k", maxSizeMessage="L'image est trop lourde ({{ size }} ko). La taille maximum autorisée est de {{ limit }} ko.") */ private $file; /** * * @ORM\\ManyToOne(targetEntity="Core\\PageBundle\\Entity\\Page", cascade={"persist"}) * @ORM\\JoinColumn(nullable=true) */ private $page; /** * @var integer $order * @ORM\\Column(name="order", type="integer", nullable=true) */ private $order; /** * Get id * * @return integer */ public function getId() { return $this->id; } public function getUploadRootDir(){ return __DIR__.'/../../../../web/uploads/page/gallery'; } public function getAbsolutePath(){ return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path; } /** *@ORM\\PrePersist() *@ORM\\PreUpdate() */ public function preUpload(){ $this->tempFile = $this->getAbsolutePath(); $this->oldFile = $this->getPath(); if(null != $this->file){ $this->path = sha1(uniqid(mt_rand(),true)).'.'.$this->file->guessExtension(); } } /** *@ORM\\PostPersist() *@ORM\\PostUpdate() */ public function upload(){ if(null != $this->file){ $this->file->move($this->getUploadRootDir(),$this->path); unset($this->file); } if($this->oldFile != null){ unlink($this->tempFile); } } /** *@ORM\\PreRemove() */ public function preRemoveUpload(){ $this->tempFile = $this->getAbsolutePath(); } /** *@ORM\\PostRemove() */ public function removeUpload(){ if(file_exists($this->tempFile)){ unlink($this->tempFile); } } public function getPath(){ return $this->path; } public function __toString(){ return $this->getName(); } /** * Set path * * @param string $path * @return Media */ public function setPath($path) { $this->path = $path; return $this; } /** * Set page * * @param \\Core\\PageBundle\\Entity\\Page $page * @return Gallery */ public function setPage(\\Core\\PageBundle\\Entity\\Page $page = null) { $this->page = $page; return $this; } /** * Get page * * @return \\Core\\PageBundle\\Entity\\Page */ public function getPage() { return $this->page; } /** * Set order * * @param integer $order * @return Gallery */ public function setOrder($order) { $this->order = $order; return $this; } /** * Get order * * @return integer */ public function getOrder() { return $this->order; } public function setFile($file) { $this->file = $file; // On vérifie si on avait déjà un fichier pour cette entité if (null !== $this->path) { // On sauvegarde l'extension du fichier pour le supprimer plus tard $this->tempFile = $this->path; // On réinitialise les valeurs des attributs url et alt $this->path = null; } } public function getFile() { return $this->file; } } 

And this is the action of my controller :

 public function createGalleryAction(Request $request, $slug){ $entity = new Gallery(); $em = $this->getDoctrine()->getManager(); $page = $em->getRepository('PageBundle:Page')->findOneBySlug($slug); $page = $em->getRepository('PageBundle:Page')->find($page->getId()); $entity->setPage($page); $form = $this->createForm(new GalleryType(), $entity); $form->bind($request); if ($form->isValid()) { $em->persist($entity); $em->flush(); $this->get('session')->getFlashBag()->add('success', 'L\\'image a été crée !'); if(isset($_POST['create_new'])){ return $this->redirect($this->generateUrl('pa_gallery_new', array('slug' => $slug))); }else{ return $this->redirect($this->generateUrl('pa_gallery_show', array('slug' => $slug) )); } } return $this->render('::crudGenerator/new.html.twig', array( 'entity' => $entity, 'form' => $form->createView(), 'actionList' => $this->generateUrl('pa'), 'actionGalleryList' => $this->generateUrl('pa_gallery_show', array('slug' => $slug)), 'actionCreate' => $this->generateUrl('pa_gallery_create', array('slug' => $slug)), 'name' => 'page', 'subName' => 'galerie photos', )); } 

order is a reserved keyword in mysql (used for order by ) and naming your column after a reserved keyword is causing the syntax error. Renaming your order field to something else should fix the problem.

https://dev.mysql.com/doc/refman/5.0/en/keywords.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM