我希望sales_flat_quote
表中的数据reserved_order_id
为空。我写道。
<?php
require_once 'abstract.php';
require_once 'cache.php';
class Mage_Migrate_Carts extends Mage_Shell_Abstract
{
public function run(){
$quotes = Mage::getModel('sales/quote');
$readConnection = $quotes->getConnection('core_read');
$query = "Select * from sales_flat_quote where reserved_order_id is Null";
$results = $readConnection->fetchAll($query);
print_r($results);
}
}
$shell = new Mage_Migrate_Carts();
$shell->run();
它正在运行它的投掷错误:Fatal error: Call to a member function fetchAll() on a non-object in file.php on line 11
。如何在销售/报价模型中编写sqlquery
。我今天第一次接触了Magento。
答案 0 :(得分:1)
您需要添加core/resource
才能阅读查询。
public function run(){
$quotes = Mage::getModel('sales/quote');
$connectionresource = Mage::getSingleton('core/resource');
$readConnection = $connectionresource->getConnection('core_read');
$query = "Select * from sales_flat_quote where reserved_order_id is Null";
$results = $readConnection->fetchAll($query);
print_r($results);
}