SQL Statements direkt auf der Magento-Datenbank ausführen

<?php

    /**
     * Get the resource model
     */
    $resource = Mage::getSingleton('core/resource');

    /**
     * Retrieve the read connection
     */
    $readConnection = $resource->getConnection('core_read');

    /**
     * Retrieve our table name
     */
    $table = $resource->getTableName('catalog/product');

    /**
     * Set the product ID
     */
    $productId = 44;

    $query = 'SELECT sku FROM ' . $table . ' WHERE entity_id = '
             . (int)$productId . ' LIMIT 1';

    /**
     * Execute the query and store the result in $sku
     */
    $sku = $readConnection->fetchOne($query);

    /**
     * Print the SKU to the screen
     */
    echo 'SKU: ' . $sku . '<br/>';

Quelle: http://fishpig.co.uk/blog/direct-sql-queries-magento.html

Schreibe einen Kommentar

Menü schließen