Magento: How to get a SQL query to download a product?

What is the complete SQL query to download the product?

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 the collection object via printLogQuery. Example: -

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

I could not find one to download the product (). Any idea?

+5
source share
6 answers

load()- actually a method that executes a query in a database. For this reason, there is no way to "find such a product load()." A final request is generated prior to the method load().

Additionally, the easiest way is to get a request on the screen, for example (in your example):

$collection = Mage::getModel('catalog/product')->getCollection();
echo $collection->getSelect()->__toString();
+25
source

You can reset the actual request with

SQL Debugging,

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

98

protected $_debug = false;

protected $_debug = true;

SQL 126

protected $_debugFile           = 'var/debug/pdo_mysql.log';
+6

.

load() Mage_Eav_Model_Entity_Abstract, , .

+1

Well $ → getSelect(), ,

$product_sku = 'sku';
$products = Mage::getResourceModel('catalog/product_collection')
  ->addAttributeToSelect('*')
  ->addAttributeToFilter('sku', $product_sku);
echo $products->getSelect();

echo

SELECT e. * FROM catalog_product_entity AS e WHERE (e.sku = 'slickerBrush_config')

0

To find out that all requests are triggered when the method is called → load () for any modal. Better check out the mysql.log file. Check if your mysql loggin is enabled or add it to my.cnf and then restart the MySQL server:

general_log = 1
log=/var/log/mysqld_query.log

In most cases, these two lines are commented out or not specified better, check in other conf as well as my.conf, mysql.conf, etc. Also, from time to time, this file or its size grows very quickly, most of the server memory can go away.

Hooray!

0
source

All Articles