2015-05-19 124 views
-3

自从我将DateTime $ date变量添加到实体后,我得到此错误,我无法插入当前日期或将修复添加到数据库。我遇到这个错误:将当前日期插入数据库

INSERT INTO repaires(EXPDATE,repaires,货币,价格,日期,cars_id,garages_id)VALUES '使用参数["(,,,,,,???????) 2016年7月12日","窗口"," $ ",400,空,1,5]

...我已经寻找3H互联网,但没有得到任何结果。 PLZ帮助。

<?php 

    namespace OBCarsTest2Bundle\Controller; 


    use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
    use Symfony\Component\HttpFoundation\Response; 
    use Symfony\Component\HttpFoundation\RedirectResponse; 
    use Symfony\Component\HttpFoundation\Request; 
    use Symfony\Component\Validator\Constraints\DateTime; 
    use OBCarsTest2Bundle\Entity\repaires; 
    use OBCarsTest2Bundle\Entity\garages; 
    use OBCarsTest2Bundle\Entity\cars; 
    use OBCarsTest2Bundle\Entity\garagesBrands; 
    use OBCarsTest2Bundle\Entity\brands; 
    use Doctrine\ORM\EntityRepository; 

    class RepairesController extends Controller 
    { 
     public function addRepairesAction($vin,$repair,$garage,$expDate,$price,$currency)//function to insert the repairs in the database 
     { 
      $addRepaires = new repaires(); 
      //$addBrandToGarage = new garagesBrands(); 

      $CarToRepaire = $this->getDoctrine()->getManager()->getRepository('OBCarsTest2Bundle:cars')->findOneByvin($vin); 
      $GarageOfRepaire = $this->getDoctrine()->getManager()->getRepository('OBCarsTest2Bundle:garages')->findOneByname($garage); 
      //$GarageBrand = $this->getDoctrine()->getManager()->getRepository('OBCarsTest2Bundle:garagesBrands')->findByidGarage($GarageOfRepaire); 

      $idBrand = $CarToRepaire->getBrands(); 
      $CheckCarBrand = $this->getDoctrine()->getManager()->getRepository('OBCarsTest2Bundle:brands')->findOneById($idBrand); 

      //to compare the dates=> expiry dates 
      $DateExp = date_create($expDate); 

      $Date = date("Y-m-d"); 
      $Today = date_create($Date); 

      $diff=date_diff($Today,$DateExp); 
      $limite = $diff->format("%R%a days"); 

      if($CarToRepaire != Null && $GarageOfRepaire != Null && 0<$limite) 
      { 
       //to insert the repaires of the users 
       $addRepaires->setPrice($price) 
          ->setRepaires($repair) 
          ->setIdGarages($GarageOfRepaire) 
          ->setIdCars($CarToRepaire) 
          ->setCurrency($currency) 
          ->setExpDate($DateExp) 
          ->setDate(date("Y-m-d")); 

       $em1 = $this->getDoctrine()->getEntityManager(); 
       $em1->persist($addRepaires); 
       $em1->flush(); 
       } 
      } 
    } 

是这样的实体:

<?php 

namespace OBCarsTest2Bundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* repaires 
* 
* @ORM\Table() 
* @ORM\Entity(repositoryClass="OBCarsTest2Bundle\Entity\repairesRepository") 
*/ 
class repaires 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

    /** 
    * @var \DateTime 
    * 
    * @ORM\Column(name="expDate", type="date") 
    */ 
    private $expDate; 

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

    /** 
    * @var string 
    * 
    * @ORM\Column(name="currency", type="string", length=50) 
    */ 
    private $currency; 

    /** 
    * @var integer 
    * 
    * @ORM\Column(name="price", type="bigint") 
    */ 
    private $price; 

    /** 
    * @var \DateTime 
    * 
    * @ORM\Column(name="date", type="date") 
    */ 
    private $date; 

    /** 
    * @var string 
    * @ORM\ManyToOne(targetEntity="cars", inversedBy="repaires") 
    * @ORM\JoinColumn(name="cars_id", referencedColumnName="id") 
    **/ 
    private $idCars; 

    /** 
    * @var string 
    * @ORM\ManyToOne(targetEntity="garages", inversedBy="repaires") 
    * @ORM\JoinColumn(name="garages_id", referencedColumnName="id") 
    **/ 
    private $idGarages; 


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

    /** 
    * Set expDate 
    * 
    * @param \DateTime $expDate 
    * @return repaires 
    */ 
    public function setExpDate($expDate) 
    { 
     $this->expDate = $expDate; 

     return $this; 
    } 

    /** 
    * Get expDate 
    * 
    * @return \DateTime 
    */ 
    public function getExpDate() 
    { 
     return $this->expDate; 
    } 

    /** 
    * Set repaires 
    * 
    * @param string $repaires 
    * @return repaires 
    */ 
    public function setRepaires($repaires) 
    { 
     $this->repaires = $repaires; 

     return $this; 
    } 

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

    /** 
    * Set currency 
    * 
    * @param string $currency 
    * @return repaires 
    */ 
    public function setCurrency($currency) 
    { 
     $this->currency = $currency; 

     return $this; 
    } 

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

    /** 
    * Set price 
    * 
    * @param integer $price 
    * @return repaires 
    */ 
    public function setPrice($price) 
    { 
     $this->price = $price; 

     return $this; 
    } 

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

    /** 
    * Set idGarages 
    * 
    * @param integer $idGarages 
    * @return repaires 
    **/ 
    public function setIdGarages($idGarages) 
    { 
     $this->idGarages = $idGarages; 

     return $this; 
    } 

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

    /** 
    * Set idCars 
    * 
    * @param integer $idCars 
    * @return repaires 
    **/ 
    public function setIdCars($idCars) 
    { 
     $this->idCars = $idCars; 

     return $this; 
    } 

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

    /** 
    * Set Date 
    * 
    * @param \DateTime $date 
    * @return repaires 
    */ 
    public function setDate($date) 
    { 
     $this->Date = $date; 

     return $this; 
    } 

    /** 
    * Get Date 
    * 
    * @return \DateTime 
    */ 
    public function getDate() 
    { 
     return $this->Date; 
    } 
} 
+4

插入的代码在哪里?问题可能在那里,谁知道。你的问题;并不是真正的问题的形式,也没有提到你是否得到了任何错误,但如果你正在检查它们,那么你一个人也不会。 –

+0

抱歉,以这种方式提问,但我绝望 – daroum

+0

请不要在评论中删除代码。属于你的问题以及你可能有的任何相关信息,这将有助于好人“帮助你”;-)请从评论区删除,提前致谢。 –

回答

0

错误实体的setDate和GETDATE变数名称。将$ this-> Date更改为$ this-> date。