How do I print all the queries in Magento?

debugging, magento, mysql, php

Solution

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 need 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)

Problem

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

Original source