There are a couple things you should read first, in the official DBI documentation:
For a CGI script, I typically do this:
$dbh->trace(2, "/tmp/pbupdate_dbilog.$$");The generated log files are a bit hard to read. This Vim syntax file makes reading them slightly easier:
:set syntax=dbi_traceAn example session of me focusing on the SQL statements that were run:
rm -f /var/tmp/sql.log # the next line appends, not overwritesDBI_TRACE='1=/var/tmp/sql.log' perl script.plgrep "FETCH('Statement')\|prepare_cached\|bind_param" /var/tmp/sql.log | lessMore verbose:
DBI_TRACE='2=/var/tmp/sql.log' perl script.plgrep -i 'prepare for .*\| execute for .*\|Binding parameters.*\|parse_params .*\|dbd_st_execute returning.*row_num.*\|fetchrow_array= .*\|dbd_st_fetch.*currow.*' /var/tmp/sql.log | lessEven more verbose, which includes the data returned in the result set:
DBI_TRACE='SQL|4=/var/tmp/sql.log' perl script.plgrep 'FETCH= \[' /var/tmp/sql.log | less