获取 - 调试SQL查询 - Magento

How can i get the SQL query of this?

$product = Mage::getModel('catalog/product')->load(4329)->getCategoryIds();

To enable the sql debugging in magento , open the file lib/Varien/Db/Adapter/Pdo/Mysql.php in your favorite text editor. Down around line 86, you’ll see the following class variables:

    /*
     * Write SQL debug data to file
     *
     * @var bool
     */
    protected $_debug               = false;
    /**
     * Minimum query duration time to be logged
     *
     * @var unknown_type
     */
    protected $_logQueryTime        = 0.05; 
    /**
     * Log all queries (ignored minimum query duration time)
     *
     * @var bool
     */
    protected $_logAllQueries       = false;
    /**
     * Add to log call stack data (backtrace)
     *
     * @var bool
     */
    protected $_logCallStack        = false;
    /**
     * Path to SQL debug data log
     *
     * @var string
     */
    protected $_debugFile           = 'var/debug/sql.txt';

Change the following variables :

 protected $_debug               = true; //false;

And

 protected $_logAllQueries       = true; //false;.

This is all.After running app goto sql.txt you will see all the queries .

echo Mage::getModel('catalog/product')->load(4329)->getCategoryIds()->getSelect();

should work

On Objects of Type Zend_Db_Select (eg Varien_DB_Select) you can call the Method assemble() to get the SQL-Query String.