我在 Symfony2 中有三个 SQL 语句,它们都使用一个包含记录 ID 的变量(使用 URL 传递)。第一个 SQL 语句可以正常工作,但是其他两个不能正常工作。它们通常会导致如下错误:
执行 'SELECT m0_.name AS name0, m0_.created AS created1, m0_.event_date AS event_date2, m0_.description AS description3, m0_.event_type AS event_type4, m1_.surname AS surname5, m1_.first_name AS first_name6 FROM map_lists 时发生异常m0_ 左连接 map_list_members m2_ ON (m2_.list_id = m0_.id) 左连接 map_contacts m1_ ON (m1_.id = m2_.contact_id) 在哪里 m0_.branch_id = ?并且 m0_.event_type 不是 NULL 并且 m1_.id = ? ORDER BY m0_.event_date DESC' 带参数 {"1":"0","2":{}}:
可捕获的致命错误:Doctrine\ORM\Query 类的对象无法转换为 F:\wamp\www\centredb\vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php 行 1211 中的字符串
有问题的两个 SQL 语句是:
// Retrieve Test For That Member
$membertests = $dm->createQuery('
SELECT mt.id, mt.taken, mt.result, mtd.test, mtd.description
FROM InstructorBundle:MapTests mt
LEFT JOIN InstructorBundle:MapTestDescriptions mtd WHERE mtd.id = mt.testDescription
WHERE mt.contact = :member'
)->setParameter('member', '40264');
$memtest = $membertests->getResult();
// Retrieve Events For That Member
$memberevents = $dm->createQuery('
SELECT mli.name, mli.created, mli.eventDate, mli.description, mli.eventType, mc.surname, mc.firstName
FROM InstructorBundle:MapLists mli
LEFT JOIN InstructorBundle:MapListMembers mlm WHERE mlm.list = mli.id
LEFT JOIN InstructorBundle:MapContacts mc WHERE mc.id = mlm.contact
WHERE mli.branch = :centre
AND mli.eventType IS NOT NULL
AND mc.id = :member
ORDER BY mli.eventDate DESC'
)->setParameters(array(
'centre' => $centreid,
'member' => $member
));
$memevent = $memberevents->getResult();
现在,如果我$member
从参数中删除并将其替换为我在开发期间使用的记录 ID,这些 SQL 语句将起作用。显然这并不理想,因此找出这些 SQL 语句在使用第 3 个使用的相同变量时为什么会失败至关重要。
第 3 条 SQL 语句,供参考,为:
// Retrieve Member Details
$member = $dm->createQuery('
SELECT mc.id, mc.surname, mc.firstName
FROM InstructorBundle:MapSubscriptions msu
LEFT JOIN InstructorBundle:MapContacts mc WHERE msu.contact = mc.id
LEFT JOIN InstructorBundle:MapFamilies mf WHERE mc.family = mf.id
WHERE mc.id = :member'
)->setParameter('member', $member);
我查看了两个表的实体和$member
用于从中恢复数据的两个字段。它们看起来像这样:
地图测试山
/**
* @var \MapContacts
*
* @ORM\ManyToOne(targetEntity="MapContacts")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="contact_id", referencedColumnName="id")
* })
*/
private $contact;
/**
* Set contact
*
* @param \Acme\InstructorBundle\Entity\MapContacts $contact
* @return MapTests
*/
public function setContact(\Acme\InstructorBundle\Entity\MapContacts $contact = null)
{
$this->contact = $contact;
return $this;
}
/**
* Get contact
*
* @return \Acme\InstructorBundle\Entity\MapContacts
*/
public function getContact()
{
return $this->contact;
}
MapContacts mc
/**
* @var integer
*
* @ORM\Column(name="id", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
我想不通,对我来说似乎很好。但显然有些东西阻止了它的工作。