Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: How to get SQL query of Product load?

Tags:

sql

magento

What is the full SQL query for product load?

I mean, how to get the full SQL query for this code:-

$productId = 52;
$product = Mage::getModel('catalog/product')->load($productId);

I know, we can get the SQL query for collection object through printLogQuery. Example:-

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->printLogQuery(true);

I couldn't find such for product load(). Any idea?

like image 370
Mukesh Chapagain Avatar asked Mar 23 '12 13:03

Mukesh Chapagain


2 Answers

load() is actually the method which execute query on database. For that reason there is no option to "find such for product load()". Final query is generated before load() method.

Additionaly, easier method to get query on the screen for example is (on your example):

$collection = Mage::getModel('catalog/product')->getCollection();
echo $collection->getSelect()->__toString();
like image 54
Łukasz L. Avatar answered Oct 10 '22 06:10

Łukasz L.


You can dump the actual query via

To enable SQL Debugging, Go to

lib/Varien/Db/Adapter/Pdo/Mysql.php

change line 98

protected $_debug = false;

to

protected $_debug = true;

It will write the SQL straight to the value of line 126

protected $_debugFile           = 'var/debug/pdo_mysql.log';
like image 35
Vern Burton Avatar answered Oct 10 '22 08:10

Vern Burton