Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm redirecting DBI trace to a file from within a CGI script.
The script contains some info but not the sql query.
There has to be something wrong with the environment becuase in other servers I can see the sql output
Any htoughts?

Replies are listed 'Best First'.
Re: DBI trace and Apache
by Corion (Patriarch) on Sep 14, 2019 at 07:21 UTC

    Maybe it is your version of DBI on that machine?

    You can output that by using

    print "Installed DB driver versions, and DBI version:\n"; DBI->installed_versions;

    This will output something like:

    Perl : 5.028001 (x86_64-linux-gnu-thread-multi) OS : linux (4.9.0) DBI : 1.642 DBD::Sponge : 12.010003 DBD::SQLite : 1.64 DBD::Proxy : install_driver(Proxy) failed: Can't locate RPC/PlC +lient.pm in @INC (you may need to install the RPC::PlClient module) DBD::Mem : 0.001 DBD::Gofer : 0.015327 DBD::File : 0.44 DBD::ExampleP : 12.014311 DBD::DBM : 0.08

    Alternatively, you can hook into the execution of SQL statements and output them yourself (if the version of DBI is recent enough):

    sub dbh_install( $self, $dbh ) { my $previous_handler = $dbh->{HandleError}; $dbh->{Callbacks} = { prepare => sub { my ($dbh, $query, $attrs) = @_; print "Preparing q{$query}\n" }, execute => sub { print "Executing ", shift->{Statement}, "\n"; } }; }