20.3. DBI Debug TechniquesSometimes the code that talks to the database server doesn't seem to work. It's important to know how to debug this code at the DBI level. Here is how this debugging can be accomplished. To log a trace of DBIstatement execution, you must set the DBI_TRACE environment variable. The PerlSetEnv DBI_TRACE directive must appear before you load Apache::DBI and DBI. For example, if you use Apache::DBI, modify your httpd.conf file with: PerlSetEnv DBI_TRACE "3=~/tmp/dbitrace.log" PerlModule Apache::DBI Replace 3 with the trace level you want. The traces from each request will be appended to /tmp/dbitrace.log. Note that the logs will probably be interleaved if requests are processed concurrently. Within your code, you can control trace generation with the trace( ) method: DBI->trace($trace_level) DBI->trace($trace_level, $trace_filename) DBI trace information can be enabled for all handles using this DBI class method. To enable trace information for a specific handle, use the similar $dbh->trace method. Using the trace option with a $dbh or $sth handle is useful to limit the trace information to the specific bit of code that you are debugging. The trace levels are:
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|