Php Symfony SQL错误消息:“0”;SQLSTATE[42000]:语法错误或访问冲突:1064“;
我有一个我不理解的错误: 执行“插入到achats(年/月)时发生异常, 模型,代码参考,日期,日期, 重要性、顺序、类型、位置(数据)值(?, 带参数[“2020-07”,“St\u2011Luc (echo\u2011graphie)”,空,“2020-01-23”,2.97,“2020-01-23”,空, 13、24、7]: SQLSTATE[42000]:语法错误或访问冲突:1064您有 SQL语法错误;检查与您的产品相对应的手册 MySQL服务器版本,以便在“年\月”附近使用正确的语法, 模型、代码参考、日期、日期、日期、重要性' 在1号线 我的实体是:Php Symfony SQL错误消息:“0”;SQLSTATE[42000]:语法错误或访问冲突:1064“;,php,mysql,symfony,Php,Mysql,Symfony,我有一个我不理解的错误: 执行“插入到achats(年/月)时发生异常, 模型,代码参考,日期,日期, 重要性、顺序、类型、位置(数据)值(?, 带参数[“2020-07”,“St\u2011Luc (echo\u2011graphie)”,空,“2020-01-23”,2.97,“2020-01-23”,空, 13、24、7]: SQLSTATE[42000]:语法错误或访问冲突:1064您有 SQL语法错误;检查与您的产品相对应的手册 MySQL服务器版本,以便在“年\月”附近使用正确的语法
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Achats
*
* @ORM\Table(name="achats", indexes={@ORM\Index(name="type", columns={"type", "location_de_achat"}), @ORM\Index(name="location_de_achat", columns={"location_de_achat"}), @ORM\Index(name="Modele", columns={"Modele"}), @ORM\Index(name="IDX_9920924E8CDE5729", columns={"type"})})
* @ORM\Entity
*/
class Achats
{
/**
* @var int
*
* @ORM\Column(name="id", type="bigint", nullable=false, options={"unsigned"=true})
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
* @return Achats
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
//=======================================================================================
/**
* @ORM\Column(name="year_month", type="string", length=255)
* @Assert\Length(
* min = 7,
* max = 7,
* minMessage = "Your date name must be at least {{ limit }} characters long",
* maxMessage = "Your date name cannot be longer than {{ limit }} characters"
* )
*/
private $yearMonth;
public function getYearMonth(): ?string
{
return $this->yearMonth;
}
public function setYearMonth(string $yearMonth): self
{
$this->yearMonth = $yearMonth;
return $this;
}
//=======================================================================================
/**
* @var string|null
*
* @ORM\Column(name="modele", type="string", length=255, nullable=true)
*/
private $modele;
/**
* @return string|null
*/
public function getModele()
{
return $this->modele;
}
/**
* @param string|null $modele
* @return Achats
*/
public function setModele($modele)
{
$this->modele = $modele;
return $this;
}
//=======================================================================================
/**
* @var string|null
*
* @ORM\Column(name="code_reference", type="string", length=255, nullable=true)
*/
private $codeReference;
/**
* @return string|null
*/
public function getCodeReference()
{
return $this->codeReference;
}
/**
* @param string|null $codeReference
* @return Achats
*/
public function setCodeReference($codeReference)
{
$this->codeReference = $codeReference;
return $this;
}
//=======================================================================================
/**
* @var \DateTime|null
*
* @ORM\Column(name="date_de_ajout", type="date", nullable=true)
*/
private $dateDeAjout;
/**
* @return \DateTime|null
*/
public function getDateDeAjout()
{
return $this->dateDeAjout;
}
/**
* @param \DateTime|null $dateDeAjout
* @return Achats
*/
public function setDateDeAjout($dateDeAjout)
{
$this->dateDeAjout = $dateDeAjout;
return $this;
}
//=======================================================================================
/**
* @var int|null
*
* @ORM\Column(name="cout", type="float", nullable=true, options={"unsigned"=true})
*/
private $cout;
/**
* @return int|null
*/
public function getCout()
{
return $this->cout;
}
/**
* @param int|null $cout
* @return Achats
*/
public function setCout($cout)
{
$this->cout = $cout;
return $this;
}
//=======================================================================================
/**
* @var \DateTime|null
*
* @ORM\Column(name="date_de_achat", type="date", nullable=true)
*/
private $dateDeAchat;
/**
* @return \DateTime|null
*/
public function getDateDeAchat()
{
return $this->dateDeAchat;
}
/**
* @param \DateTime|null $dateDeAchat
* @return Achats
*/
public function setDateDeAchat($dateDeAchat)
{
$this->dateDeAchat = $dateDeAchat;
return $this;
}
//=======================================================================================
/**
* @var \Types
*
* @ORM\ManyToOne(targetEntity="Types")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="type", referencedColumnName="id")
* })
*/
private $type;
/**
* @return \Types
*/
public function getType()
{
return $this->type;
}
/**
* @param \Types $type
* @return Achats
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
//=======================================================================================
/**
* @var \Lieux
*
* @ORM\ManyToOne(targetEntity="Lieux")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="location_de_achat", referencedColumnName="id")
* })
*/
private $locationDeAchat;
/**
* @return \Lieux
*/
public function getLocationDeAchat()
{
return $this->locationDeAchat;
}
/**
* @param \Lieux $locationDeAchat
* @return Achats
*/
public function setLocationDeAchat($locationDeAchat)
{
$this->locationDeAchat = $locationDeAchat;
return $this;
}
//=======================================================================================
/**
* @ORM\Column(type="smallint", nullable=true)
*/
private $importance;
public function getImportance(): ?int
{
return $this->importance;
}
public function setImportance(?int $importance): self
{
$this->importance = $importance;
return $this;
}
//=======================================================================================
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $ordre;
public function getOrdre(): ?int
{
return $this->ordre;
}
public function setOrdre(?int $ordre): self
{
$this->ordre = $ordre;
return $this;
}
}
yearMonth;
}
公共函数setYearMonth(字符串$yearMonth):self
{
$this->yearMonth=$yearMonth;
退还$this;
}
//=======================================================================================
/**
*@var字符串|空
*
*@ORM\Column(name=“modele”,type=“string”,length=255,nullable=true)
*/
私人$modele;
/**
*@返回字符串|空
*/
公共函数getModele()
{
返回$this->modele;
}
/**
*@param string | null$modele
*@return-Achats
*/
公共函数setModele($modele)
{
$this->modele=$modele;
退还$this;
}
//=======================================================================================
/**
*@var字符串|空
*
*@ORM\Column(name=“code\u reference”,type=“string”,length=255,nullable=true)
*/
私人参考;
/**
*@返回字符串|空
*/
公共函数getCodeReference()
{
返回$this->coderence;
}
/**
*@param string | null$codeReference
*@return-Achats
*/
公共函数setCodeReference($codeReference)
{
$this->coderence=$coderence;
退还$this;
}
//=======================================================================================
/**
*@var\DateTime |空
*
*@ORM\Column(name=“date\u de\u ajout”,type=“date”,nullable=true)
*/
私人$dateDeAjout;
/**
*@return\DateTime |空
*/
公共函数getDateDeAjout()
{
返回$this->dateDeAjout;
}
/**
*@param\DateTime | null$dateDeAjout
*@return-Achats
*/
公共函数setDateDeAjout($dateDeAjout)
{
$this->dateDeAjout=$dateDeAjout;
退还$this;
}
//=======================================================================================
/**
*@var int|null
*
*@ORM\Column(name=“cout”,type=“float”,nullable=true,options={“unsigned”=true})
*/
私人$cout;
/**
*@return int|null
*/
公共函数getCout()
{
返回$this->cout;
}
/**
*@param int | null$cout
*@return-Achats
*/
公共函数setCout($cout)
{
$this->cout=$cout;
退还$this;
}
//=======================================================================================
/**
*@var\DateTime |空
*
*@ORM\Column(name=“date\u de\u achat”,type=“date”,nullable=true)
*/
私人$DateDeChat;
/**
*@return\DateTime |空
*/
公共函数getDateDeAchat()
{
返回$this->dateDeAchat;
}
/**
*@param\DateTime | null$dateDeAchat
*@return-Achats
*/
公共函数setDateDeChat($DateDeChat)
{
$this->dateDeAchat=$dateDeAchat;
退还$this;
}
//=======================================================================================
/**
*@var\Types
*
*@ORM\manytone(targetEntity=“Types”)
*@ORM\JoinColumns({
*@ORM\JoinColumn(name=“type”,referencedColumnName=“id”)
* })
*/
私人$type;
/**
*@return\Types
*/
公共函数getType()
{
返回$this->type;
}
/**
*@param\Types$type
*@return-Achats
*/
公共函数setType($type)
{
$this->type=$type;
退还$this;
}
//=======================================================================================
/**
*@var\Lieux
*
*@ORM\ManyToOne(targetEntity=“Lieux”)
*@ORM\JoinColumns({
*@ORM\JoinColumn(name=“location\u de\u achat”,referencedColumnName=“id”)
* })
*/
私人$locationDeAchat;
/**
*@return\Lieux
*/
公共函数getLocationDeChat()
{
返回$this->locationDeAchat;
}
/**
*@param\Lieux$locationDeAchat
*@return-Achats
*/
公共函数setLocationDeChat($LocationDeChat)
{
$this->locationDeAchat=$locationDeAchat;
退还$this;
}
//=======================================================================================
/**
*@ORM\Column(type=“smallint”,nullable=true)
*/
私人部门的重要性;
公共函数getImportance():?int
{
返回$this->importance;
}
公共功能设置重要性(?int$重要性):自我
{
$this->importance=$importance;
退还$this;
}
//=======================================================================================
/**
*@ORM\Column(type=“integer”,nullable=true)
*/
私人订单;
公共函数getOrdre():?int
{
返回$this->ordre;
}
公共函数setOrdre(?int$ordre):self
{
$this->ordre=$ordre;
退还$this;
}
}
控制器:
<?php
namespace App\Controller;
use App\Entity\Achats;
use App\Form\AchatsType;
use App\Form\AchatsNewType;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/")
*/
class AchatsController extends AbstractController
{
/**
* @Route("/", name="achats_index", methods={"GET"})
*/
public function index(): Response
{
$achats = $this->getDoctrine()
->getRepository(Achats::class)
->findAll();
return $this->render('achats/index.html.twig', [
'achats' => $achats,
]);
}
/**
* @Route("/achats/new", name="achats_new", methods={"GET","POST"})
* @param Request $request
* @return Response
* @throws Exception
*/
public function new(Request $request): Response
{
$achat = new Achats();
$form = $this->createForm(AchatsNewType::class, $achat);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$now = new \DateTime('now');
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($achat);
$entityManager->flush();
return $this->redirectToRoute('achats_index');
}
return $this->render('achats/new.html.twig', [
'achat' => $achat,
'form' => $form->createView(),
]);
}
/**
* @Route("/achats/{id}", name="achats_show", methods={"GET"})
*/
public function show(Achats $achat): Response
{
return $this->render('achats/show.html.twig', [
'achat' => $achat,
]);
}
/**
* @Route("/achats/{id}/edit", name="achats_edit", methods={"GET","POST"})
*/
public function edit(Request $request, Achats $achat): Response
{
$form = $this->createForm(AchatsType::class, $achat);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('achats_index');
}
return $this->render('achats/edit.html.twig', [
'achat' => $achat,
'form' => $form->createView(),
]);
}
/**
* @Route("/achats/{id}", name="achats_delete", methods={"DELETE"})
*/
public function delete(Request $request, Achats $achat): Response
{
if ($this->isCsrfTokenValid('delete'.$achat->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($achat);
$entityManager->flush();
}
return $this->redirectToRoute('achats_index');
}
}
年/月
是,因此未经特殊处理不能用作列名
您需要在查询中将其括在反勾中,如下所示
`year_month`
所以哟
`year_month`