2011-06-10 81 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