2011-06-10 77 views
1

我使用zend_db_select来连接3个表格,而在结果集数组中,当我期待看到具有别名的列名时,它会返回一个没有别名的键的数组。zend db加入结果集

$dbSelect = $db->select()->from(array("pp"=>"products_photos"),array()) 
         ->joinInner(array("ph"=>"photos"), "pp.photo_id=ph.photo_id","ph.photo_id") 
         ->joinInner(array('pr'=>'products'),"pr.product_id=pp.product_id","pr.product_id") 
         ->where("pr.product_id=$row->product_id"); 

$photoJoinRowSet = $db->fetchAll($dbSelect); 
var_dump($photoJoinRowSet);die(); 

结果,如:

array(2) { [0]=> array(3) { ["product_id"]=> string(1) "1" ["photo_id"]=> string(1) "4" }} 

虽然我期待:

array(2) { [0]=> array(3) { ["pr.product_id"]=> string(1) "1" ["ph.photo_id"]=> string(1) "4" }}

......即与列别名。

有谁知道为什么会发生这种情况?谢谢。

回答

1

您没有在此处指定任何别名,因此您的选择将转化为SELECT ph.photo_id, pr.product_id之类的内容,但不包含AS,这将按预期返回photo_idproduct_id

您需要明确指定你的别名,如果你想点的按键:上Zend_Db_Select documentation

$dbSelect = $db->select()->from(array("pp"=>"products_photos"),array()) 
    ->joinInner(array("ph"=>"photos"), "pp.photo_id=ph.photo_id", 
     array("ph.photo_id" => "ph.photo_id")) 
    ->joinInner(array('pr'=>'products'), "pr.product_id=pp.product_id", 
     array("pr.product_id" => "pr.product_id")) 
    ->where("pr.product_id=$row->product_id"); 

更多信息。

+0

谢谢。 zend文档没有明确说明这一点,虽然 – krishna 2011-06-11 18:46:12

+1

我不能指责你这一点:) – Benjamin 2011-06-11 19:18:26