Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将当前日期插入数据库_Php_Mysql_Symfony_Doctrine Orm - Fatal编程技术网

Php 将当前日期插入数据库

Php 将当前日期插入数据库,php,mysql,symfony,doctrine-orm,Php,Mysql,Symfony,Doctrine Orm,自从我将DateTime$date变量添加到实体后,我就出现了这个错误,我无法插入当前日期或向数据库添加修复。我有一个错误: 使用参数[2016-07-12,窗口,$,400,空,1,5]将日期,货币,价格,日期,车辆id,车库id值插入到修理厂expDate,修理厂,货币,价格,日期中 我在网上搜索了3个小时,但没有得到任何结果。 请帮忙 <?php namespace OBCarsTest2Bundle\Controller; use Symfony\Bundle

自从我将DateTime$date变量添加到实体后,我就出现了这个错误,我无法插入当前日期或向数据库添加修复。我有一个错误:

使用参数[2016-07-12,窗口,$,400,空,1,5]将日期,货币,价格,日期,车辆id,车库id值插入到修理厂expDate,修理厂,货币,价格,日期中

我在网上搜索了3个小时,但没有得到任何结果。 请帮忙

<?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;
    }
}

setDate和getDate中的实体变量名称错误。将$this->Date更改为$this->Date。

插入代码在哪里?问题可能就在那里,谁知道呢。你的问题;不是以问题的形式,你也没有提到你是否有任何错误,但是如果你正在检查错误,你是孤独的。很抱歉这样问这个问题,但我很失望,请不要在评论中添加代码。这属于您的问题,以及您可能拥有的有助于好人帮助您的任何相关信息;-请先从评论区中删除,谢谢。我想我要重新写一个问题:P thx for your time你想用哪种格式插入当前日期?