How do I print all the queries in Magento?

后端 未结 6 1879

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

Thanks

6条回答
  •  独厮守ぢ
    2020-12-07 15:24

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

提交回复
热议问题