views:

322

answers:

2

Hi,

is it possible to display all the query strings in Magento? I really like to see what queries are executed.

Thanks

+1  A: 

The queries will vary significantly depending on your activities. If you have some control over your MySQL server, try turning on query logging:

set global general_log = on

Then you can get the SQL log to see queries. As a word or warning, Magento tends to execute dozens of queries on every page load, and hundreds to save an object.

Thanks, Joe

Joseph Mastey
+1  A: 

I'm not 100% sure this will catch every query, but most run through the query method Zend_Db_Adapter_Abstract query method in

lib/Zend/Db/Adapter/Abstract.php

With that in mind, you could temporarily add some debugging statements (to a copy you make in app/code/local/Mage to be safe)

public function query($sql, $bind = array())
{
    // connect to the database if needed
    $this->_connect();

    // is the $sql a Zend_Db_Select object?
    if ($sql instanceof Zend_Db_Select) {
        if (empty($bind)) {
            $bind = $sql->getBind();
        }

        $sql = $sql->assemble();
    }
    echo '$sql' . "\n<br />\n";
    var_dump($bind);

If you nned to catch them all, you'd be better off doing this at the mysql level (which isn't always possible depending on your host/IT situation)

Alan Storm