$resource = Mage::getSingleton(’core/resource’); $readConnection = $resource->getConnection(’core_read’); $query = ‘SELECT COUNT(id) AS rows FROM table’; $sql = $readConnection->prepare($query); $sql->execute(); $data = $sql->fetch(); printf("Rows: %d\n", $data[’rows’]);
Posted on December 20, 2017, 11:38 am, by admin, under
Tips.
addFieldToFilter() is used to filter Non-EAV collections. addAttributeToFilter() is used to filter EAV collections.
gteq – greater than or equal (>=) lteq – less then or equal () lt – less (
$tableDataCollection = Mage::getResourceModel(’modulename/tablename_collection’)->setPageSize(50); // Set number of pages and current page $pages = $tableDataCollection->getLastPageNumber(); $currentPage = 1; // Interate do { $tableDataCollection->setCurPage($currentPage); $tableDataCollection->load(); foreach ($tableDataCollection as $tableRow) { echo $tableRow->getId()."\n"; } $currentPage++; //Clear collection and free memory $tableDataCollection->clear(); } while ($pages => $currentPage);
Method 1 <?php require_once dirname(__DIR__) . ‘/../../../../../app/Mage.php’; $app = Mage::app(); Mage::register(’isSecureArea’, true); // your code goes here or <?php require_once dirname(__DIR__) . ‘/../../../../../app/Mage.php’; /** * Class My Shell Class */ class My_Shell_Class { /** * Constructor */ public function __construct() { Mage::app(); Mage::register(’isSecureArea’, true); } /** * Custom function */ […]