douqiu0351 2015-05-19 12:46
浏览 40

将当前日期插入数据库

i am getting this error ever since i added the DateTime $date variable to the entity i can't insert the current date or add a repair to the database. i'm having this error :

INSERT INTO repaires (expDate, repaires, currency, price, date, cars_id, garages_id) VALUES (?, ?, ?, ?, ?, ?, ?)' with params ["2016-07-12", "window", "$", 400, null, 1, 5]

i have searched the internet for 3h but didn't get any results. plz help.

<?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\Entityepaires;
    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();
                }
          }
    }

that's the entity :

<?php

namespace OBCarsTest2Bundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * repaires
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="OBCarsTest2Bundle\EntityepairesRepository")
 */
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;
    }
}
  • 写回答

1条回答 默认 最新

  • douli1872 2015-05-21 13:28
    关注

    Wrong entity var name in setDate and getDate. Change $this->Date to $this->date.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,