0

i have two entities template and div their code is as follows: (i generated it automatically via console)

    <?php

namespace Tun\PublicBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Tun\PublicBundle\Entity\Template
 *
 * @ORM\Table(name="template")
 * @ORM\Entity
 */
class Template
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string $name
     *
     * @ORM\Column(name="name", type="string", length=255, nullable=true)
     */
    private $name;

    /**
     * @var integer $nbreDiv
     *
     * @ORM\Column(name="nbre_div", type="integer", nullable=false)
     */
    private $nbreDiv;



    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set nbreDiv
     *
     * @param integer $nbreDiv
     */
    public function setNbreDiv($nbreDiv)
    {
        $this->nbreDiv = $nbreDiv;
    }

    /**
     * Get nbreDiv
     *
     * @return integer 
     */
    public function getNbreDiv()
    {
        return $this->nbreDiv;
    }
}

div:

<?php

namespace Tun\PublicBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Tun\PublicBundle\Entity\Div
 *
 * @ORM\Table(name="div")
 * @ORM\Entity
 */
class Div
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var integer $hauteur
     *
     * @ORM\Column(name="hauteur", type="integer", nullable=false)
     */
    private $hauteur;

    /**
     * @var integer $largeur
     *
     * @ORM\Column(name="largeur", type="integer", nullable=false)
     */
    private $largeur;

    /**
     * @var integer $ind
     *
     * @ORM\Column(name="ind", type="integer", nullable=true)
     */
    private $ind;


    /**
     * @var string $emplacement
     *
     * @ORM\Column(name="emplacement", type="string", length=255, nullable=false)
     */
    private $emplacement;

    /**
     * @var Template
     *
     * @ORM\ManyToOne(targetEntity="Template")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="template", referencedColumnName="id")
     * })
     */
    private $template;






    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set hauteur
     *
     * @param integer $hauteur
     */
    public function setHauteur($hauteur)
    {
        $this->hauteur = $hauteur;
    }

    /**
     * Get hauteur
     *
     * @return integer 
     */
    public function getHauteur()
    {
        return $this->hauteur;
    }

    /**
     * Set largeur
     *
     * @param integer $largeur
     */
    public function setLargeur($largeur)
    {
        $this->largeur = $largeur;
    }

    /**
     * Get ind
     *
     * @return integer 
     */
    public function getInd()
    {
        return $this->ind;
    }


    /**
     * Set ind
     *
     * @param integer $ind
     */
    public function setInd($ind)
    {
        $this->ind = $ind;
    }

    /**
     * Get largeur
     *
     * @return integer 
     */
    public function getLargeur()
    {
        return $this->largeur;
    }


    /**
     * Set emplacement
     *
     * @param string $emplacement
     */
    public function setEmplacement($emplacement)
    {
        $this->emplacement = $emplacement;
    }

    /**
     * Get emplacement
     *
     * @return string 
     */
    public function getEmplacement()
    {
        return $this->emplacement;
    }

    /**
     * Set template
     *
     * @param Tun\PublicBundle\Entity\Template $template
     */
    public function setTemplate(\Tun\PublicBundle\Entity\Template $template)
    {
        $this->template = $template;
    }

    /**
     * Get template
     *
     * @return Tun\PublicBundle\Entity\Template 
     */
    public function getTemplate()
    {
        return $this->template;
    }
}

Now here is the problem, i wish to create a template then a div, so i proceeded this way:

$template= new Template();
$template->setName($name);
$template->setNbreDiv($nbre_div);
$em = $this->getDoctrine()->getEntityManager();
$em->persist($template);
$em->flush();

$d=new Div();
$d->setHauteur(100);
$d->setLargeur(100);
$d->setEmplacement("Gauche");
$d->setInd(1);
$d->setTemplate($template);
$em = $this->getDoctrine()->getEntityManager();
$em->persist($d);
$em->flush();

And i get the following error :

SQLSTATE[42000]: Syntax error or access violation: 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 'div (hauteur, largeur, ind, emplacement, template) VALUES (100, 100, 1, 'Gauche'' at line 1

Hope i put everything, thanks for help in advance. I spent the whole day trying all the combination that come to my mind ...

Thomas Kelley
  • 10,187
  • 1
  • 36
  • 43
MarGa
  • 711
  • 3
  • 10
  • 23

1 Answers1

4

DIV is a reserved keyword in MySQL. It is an operator, and is used for integer division. Example:

mysql> SELECT 35 DIV 7;
+----------+
| 35 DIV 7 |
+----------+
|        5 |
+----------+
1 row in set (0.02 sec)

My suggestion would be to rename this entity.

Reference: MySQL Arithmetic Operators

Thomas Kelley
  • 10,187
  • 1
  • 36
  • 43
  • I don't know i should be happy or embarrassed :s thank you a lot anyway – MarGa Nov 27 '12 at 21:14
  • @MarouaGasmi Don't be embarrassed! I use MySQL every day, and never knew about the `DIV` keyword until today. Just had a hunch, based on the error message you posted. Anyway, glad you got to the bottom of it! – Thomas Kelley Nov 28 '12 at 01:19