2011-01-13 43 views
7

Magento的構造其SQL查詢,如如何將Magento sql查詢顯示爲字符串?

$this->getSelect()->joinInner(
     array('sbao' => $this->getTable('sales/billing_agreement_order')), 
     'main_table.entity_id = sbao.order_id', 
     array() 
    ) 

有沒有顯示字符串格式生成的查詢,而不是如打印出的巨大物體的方式

echo $this->getSelect()->joinInner(
     array('sbao' => $this->getTable('sales/billing_agreement_order')), 
     'main_table.entity_id = sbao.order_id', 
     array() 
    )->toString(); 

回答

13
$select = $this->getSelect()->joinInner(
     array('sbao' => $this->getTable('sales/billing_agreement_order')), 
     'main_table.entity_id = sbao.order_id', 
     array() 
    ); 

echo $select; 
4

我差不多已經爲那些感興趣的人使用了 - > __ toString()例如

echo $this->getSelect()->joinInner(
    array('sbao' => $this->getTable('sales/billing_agreement_order')), 
    'main_table.entity_id = sbao.order_id', 
    array() 
)->__toString() 
+2

回聲剛好夠,因爲它有它自己的toString方法 – 2011-01-13 13:02:28

+1

,有時你需要轉換其自動觸發`__toString`方法。類似`echo(string)$ this-> getSelect ...' – clockworkgeek 2011-01-13 13:24:55