Symfony第一用户保存错误


symfony first user saving error

我尝试使用Symfony用户,但无法插入任何。

代码:

$em = $this->getDoctrine()->getManager();
 $user = new User();
        $user->setUsername('asdfsdfd');
        $user->setEmail('aa@aa.pl');
        $user->setPassword('ssfsfsdfds');
        $user->setGroup('435');
        $em->persist($user);
        $em->flush();

错误:

    An exception occurred while executing 'INSERT INTO mUsers (username, email, salt, password, is_active, last_visit, city, post_code, street, phone, first_name, last_name, group) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["asdfsdfd", "aa@aa.pl", "b24fa24886ff17ecb56226b2a09f55ee", "ssfsfsdfds", 1, null, null, null, null, null, null, null, "435"]:
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 'group) VALUES ('asdfsdfd', 'aa@aa.pl', 'b24fa24886ff17ecb56226b2a09f55ee', 'ssfs' at line 1
500 Internal Server Error - DBALException
1 linked Exception:

这里是实体

<?php
namespace Miejsce'UserBundle'Entity;
/**
 * Created by PhpStorm.
 * User: grek
 * Date: 3/13/14
 * Time: 2:31 PM
 */

use Symfony'Component'Security'Core'User'UserInterface;
use Doctrine'ORM'Mapping as ORM;
/**
 * @ORM'Entity
 * @ORM'Table(name="mUsers")
 * @ORM'Entity(repositoryClass="Miejsce'UserBundle'Repository'UserRepository")
 */
class User implements UserInterface, 'Serializable
{
    /**
     * @ORM'Column(type="integer")
     * @ORM'Id
     * @ORM'GeneratedValue(strategy="AUTO")
     */
    private $id;
    /**
     * @ORM'Column(type="string", length=25, unique=true)
     */
    private $username;
    /**
     * @ORM'Column(type="string", length=25, unique=true)
     */
    private $email;
    /**
     * @ORM'Column(type="string", length=32)
     */
    private $salt;
    /**
     * @ORM'Column(type="string", length=40)
     */
    private $password;
    /**
     * @ORM'Column(name="is_active", type="boolean")
     */
    private $isActive;
    /**
     * @ORM'Column(name="last_visit", type="integer", nullable=true)
     */
    private $lastVisit;
     /**
     * @ORM'Column(type="string", length=40, nullable=true)
     */
    private $city;
    /**
     * @ORM'Column(name="post_code", type="string", length=12, nullable=true)
     */
    private $postCode;
    /**
     * @ORM'Column(type="string", length=12, nullable=true)
     */
    private $street;
    /**
     * @ORM'Column(type="string", length=12, nullable=true)
     */
    private $phone;
    /**
     * @ORM'Column(name="first_name", type="string", length=40, nullable=true)
     */
    private $firstName;
    /**
     * @ORM'Column(name="last_name", type="string", length=40, nullable=true)
     */
    private $lastName;

    /**
     * @ORM'Column(type="string", length=12)
     */
    private $group;

    public function __construct()
    {
        $this->isActive = true;
        $this->salt = md5(uniqid(null, true));
    }
    public function getId(){
        return $this->id;
    }
    public function setId($id){
        return $this->id=$id;
    }
    /**
     * @inheritDoc
     */
    public function getUsername()
    {
        return $this->username;
    }
    /**
     * @inheritDoc
     */
    public function setUsername($username)
    {
        $this->username = $username;
        $this->email = $username;
    }
    /**
     * @inheritDoc
     */
    public function getSalt()
    {
        return $this->salt;
    }
    public function setSalt($salt)
    {
        $this->salt = $salt;
    }
    /**
     * @inheritDoc
     */
    public function getPassword()
    {
        return $this->password;
    }
    public function setPassword($password)
    {
        $this->password = $password;
    }
    /**
     * @inheritDoc
     */
    public function getRoles()
    {
        return array('ROLE_USER');
    }
    /**
     * @inheritDoc
     */
    public function eraseCredentials()
    {
    }
    /**
     * @see 'Serializable::serialize()
     */
    public function serialize()
    {
        return serialize(
            array(
                $this->id,
            )
        );
    }
    /**
     * @see 'Serializable::unserialize()
     */
    public function unserialize($serialized)
    {
        list (
            $this->id,
            ) = unserialize($serialized);
    }
    /**
     * @param mixed $city
     */
    public function setCity($city)
    {
        $this->city = $city;
    }
    /**
     * @return mixed
     */
    public function getCity()
    {
        return $this->city;
    }
    /**
     * @param mixed $email
     */
    public function setEmail($email)
    {
        $this->email = $email;
    }
    /**
     * @return mixed
     */
    public function getEmail()
    {
        return $this->email;
    }
    /**
     * @param mixed $firstName
     */
    public function setFirstName($firstName)
    {
        $this->firstName = $firstName;
    }
    /**
     * @return mixed
     */
    public function getFirstName()
    {
        return $this->firstName;
    }
    /**
     * @param mixed $group
     */
    public function setGroup($group)
    {
        $this->group = $group;
    }
    /**
     * @return mixed
     */
    public function getGroup()
    {
        return $this->group;
    }
    /**
     * @param mixed $isActive
     */
    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;
    }
    /**
     * @return mixed
     */
    public function getIsActive()
    {
        return $this->isActive;
    }
    /**
     * @param mixed $lastName
     */
    public function setLastName($lastName)
    {
        $this->lastName = $lastName;
    }
    /**
     * @return mixed
     */
    public function getLastName()
    {
        return $this->lastName;
    }
    /**
     * @param mixed $lastVisit
     */
    public function setLastVisit($lastVisit)
    {
        $this->lastVisit = $lastVisit;
    }
    /**
     * @return mixed
     */
    public function getLastVisit()
    {
        return $this->lastVisit;
    }
    /**
     * @param mixed $phone
     */
    public function setPhone($phone)
    {
        $this->phone = $phone;
    }
    /**
     * @return mixed
     */
    public function getPhone()
    {
        return $this->phone;
    }
    /**
     * @param mixed $postCode
     */
    public function setPostCode($postCode)
    {
        $this->postCode = $postCode;
    }
    /**
     * @return mixed
     */
    public function getPostCode()
    {
        return $this->postCode;
    }
    /**
     * @param mixed $street
     */
    public function setStreet($street)
    {
        $this->street = $street;
    }
    /**
     * @return mixed
     */
    public function getStreet()
    {
        return $this->street;
    }

}

Group是SQL中的保留字,最好不要调用列组或更新表来使用反引号:

/**
 * @ORM'Column(name="`group`", type="string", length=12)
 */
private $group;