1

I'm trying to get the raw sql query Magento is running on the database to select the data for the report grid. I can print the collection query string with

$collection->getSelect()->__toString()

but this does not contain the filters. But I need the query with filters. Thanks for any help

2 Answers 2

1
$collection->load();
$collection->getSelect()->__toString()

Should work. If you are using an EAV collection you have the problem, that the first query (the one you see) only loads IDs which applied the filters and afterwards loads the attributes (you don't see this query).

With @Phil's answer you see everything, which might be a little bit confusing but complete :-)

1

Go to lib/Varien/Db/Adapter/Pdo/Mysql.php and set the following variables to true:

protected $_debug
protected $_logAllQueries

You'll find the queries in var/debug/sql.txt

(Thats the only option I know though, there are probably better ones)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.