閱讀699 返回首頁    go 阿裏雲 go 技術社區[雲棲]


magento -- 在Magento中使用自己寫的SQL語句

Magento的Models Collection  很強大,使用它們可以很方便的查詢和操作數據庫。但是有些場合,因為一些特殊需求或對Magento的了解不夠深,可能會需要自己手寫SQL語句來查詢和操作數據庫。以下分別是讀寫數據庫的代碼。

 

// For Read // fetch read database connection that is used in Mage_Core module $read= Mage::getSingleton('core/resource')->getConnection('core_read'); $value=$read->query("SE..."); $row = $value->fetch(); print_r($row); // As Array  

 

   // For Write // fetch write database connection that is used in Mage_Core module $write = Mage::getSingleton('core/resource')->getConnection('core_write'); // now $write is an instance of Zend_Db_Adapter_Abstract $write->query("insert into tablename values ('aaa','bbb','ccc')");  

最後更新:2017-04-02 05:21:05

  上一篇:go ruby在windows 7 cmd 中顯示彩色文字
  下一篇:go magento 開發 -- 新增一個簡單的退貨流程