-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;
}
}
插入的代碼在哪裏?問題可能在那裏,誰知道。你的問題;並不是真正的問題的形式,也沒有提到你是否得到了任何錯誤,但如果你正在檢查它們,那麼你一個人也不會。 –
抱歉,以這種方式提問,但我絕望 – daroum
請不要在評論中刪除代碼。屬於你的問題以及你可能有的任何相關信息,這將有助於好人「幫助你」;-)請從評論區刪除,提前致謝。 –