您好我正在使用Doctrine作为我的Zend App的ORM。
我正在考虑将查询导出到csv文件,但是我得到以下输出
44 Brownie Don't feed after 8pm Array Array
所以宠物名称和他们的要求是打印出来的(出于某种原因还有他们的ID),但是宠物的品种和行为只是打印成ARRAY。
我意识到这是由于查询,因为行为和品种信息存储在结果数组中的自己的数组中,但是如何将这些值导出到文件中。 我已经尝试在查询中添加where子句,以便将宠物品种和行为与相关表的主键相匹配,但它不起作用,所以我删除了它们。
我的行动代码在
之下 public function todayscatterybookingstofileAction()
{
$today=date('y-m-d');
$q = Doctrine_Query::create()
->select('p.name,b.breed,h.behaviour,p.special_requirements')
->from('PetManager_Model_Pets p')
->leftJoin('p.PetManager_Model_Breeds b')
->leftJoin('p.PetManager_Model_Behaviour h')
->leftJoin('p.PetManager_Model_Catterypets s')
->leftJoin('s.PetManager_Model_Catterybooking k')
->where('s.bookingID = k.catterybookingID')
->andWhere('p.petID=s.pet')
->andwhere('k.srtDate < ?',$today)
->andWhere('k.edDate >= ?',$today)
->andWhere('k.catteryappointmentstatus=1');
$result = $q->fetchArray();
$description="D:/reports/Occupied Catteries";
$extension=".csv";
$filename=$description.$today.$extension;
$file = fopen($filename,"w");
foreach($result as $line)
{
fputcsv($file,$line);
}
fclose($file);
}
答案 0 :(得分:0)
如果您使用的是Doctrine 1.1或更高版本,您可以使用HYDRATE_SCALAR选项强制使用平面数组:
$q = Doctrine_Query::create()
->select('p.name,b.breed,h.behaviour,p.special_requirements')
->from('PetManager_Model_Pets p')
->leftJoin('p.PetManager_Model_Breeds b')
->leftJoin('p.PetManager_Model_Behaviour h')
->leftJoin('p.PetManager_Model_Catterypets s')
->leftJoin('s.PetManager_Model_Catterybooking k')
->where('s.bookingID = k.catterybookingID')
->andWhere('p.petID=s.pet')
->andwhere('k.srtDate < ?',$today)
->andWhere('k.edDate >= ?',$today)
->andWhere('k.catteryappointmentstatus=1')->setHydrationMode(Doctrine::HYDRATE_SCALAR);
这应该给你一个单一的清单。