zend framework stack trace

后端 未结 2 957
旧巷少年郎
旧巷少年郎 2021-01-03 10:50

Is there a way to make stack trace to display the whole generated SQL statement when there is an error instead just the first few characters of it?

This is what it c

相关标签:
2条回答
  • 2021-01-03 11:20

    whilst the profiler is V cool - it doesn't help debug when the system throws an exception..

    check out this post on giving a more detailed stack trace inc full SQL

    ONLY TO BE USED IN DEV ENVIRONMENTS for obvious reasons

    http://www.edmondscommerce.co.uk/blog/zend-framework/zend-framework-more-detailed-stack-trace/

    0 讨论(0)
  • 2021-01-03 11:45

    If you want to view the complete sql statement you can use Zend_Debug. For example if your sql statement is in the variable $select and you want to view the complete sql statement you can use the following line of code:

    Zend_Debug::Dump($select);
    exit;
    

    Or if your code is created withe the Zend_Db_Table class you can use:

    $select = new Zend_Db_Select(Zend_Registry::get('db'));
    $select->from('string');
    Zend_Debug::Dump($select->assemble());
    exit;
    

    I think the best way to view the sql statement is by using the profiling function on the database connection. This is combination withe the logging function and the firePHP add-on for Firefox is my favorite setup.

    If you use the MVC configuration of Zend Framework this is done white this lines of code:

    // setup the database connection
    $db = Zend_Db::factory(Zend_Registry::get('config')->database->adapter,Zend_Registry::get('config')->database->params);
    
    // create a new profiler
    profiler = new Zend_Db_Profiler_Firebug('All DB Queries');
    
    // enable profiling (this is only recommended in development mode, disable this in production mode)
    $profiler->setEnabled(true);
    // add the profiler to the database object
    $db->setProfiler($profiler);
    
    // setup the default adapter to use for database communication
    Zend_Db_Table_Abstract::setDefaultAdapter($db);
    
    // register the database object to access it in other parts of the project
    Zend_Registry::set('db',$db);
    
    /**
    *
    * This part is optional
    *
    * You can use this logger to log debug information to the firephp add-on for Firefox
    * This is handy for debugging but must be disabled in production mode
    *
    */
    
    // create logger
    $logger = new Zend_Log();
    
    // create firebug writer
    $firebug_writer = new Zend_Log_Writer_Firebug();
    
    // add writer to logger
    $logger->addWriter($firebug_writer);
    
    // register the logger object to access it in other parts of the project
    Zend_Registry::set('log',$logger);
    

    The firebug add-on (requirement for firephp) can be found on this website: Firebug

    The FirePHP add-on can be found on this website: FirePHP

    Ivo Trompert

    0 讨论(0)
提交回复
热议问题