in reply to DBD::Pg no errors but empty result?

Are you able to connect using DBI and DBD::Pg?

Without seeing your helper module, we can only guess. Do you properly check for connection failures?

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: DBD::Pg no errors but empty result?
by cormanaz (Deacon) on Mar 19, 2021 at 00:34 UTC
    Well don't I feel stupid. It works. I printed $n rather than "$n\n" so it output the answer then the commend prompt immediately after and I didn't notice.

    Thanks for the response and sorry for the cycles. :-/

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: DBD::Pg no errors but empty result?
by cormanaz (Deacon) on Mar 19, 2021 at 00:10 UTC
    Here's the test script that includes the helper subs. Yes I check for connection failures, whether I'm doing it the right way...
    #!/usr/bin/perl -w use DBI; my $dbh = connectpgdb('****','****','****','Pg','localhost'); my $n = getsqlvalue($dbh,"select count(*) from blog"); print $n; sub connectpgdb { # this is used to connect with DBD::Pg my ($database,$user,$password,$driver,$server) = @_; my $url; unless ($driver) { $driver = "Pg"; } unless ($server) { $url = "DBI:$driver:dbname=$database;host=localhost"; } else { $url = "DBI:$driver:dbname=$database;host=$server;port=54 +32"; } unless ($user) { $user = "****"; $password = "****"; } my $dbh = DBI->connect( $url, $user, $password,{AutoCommit=>1,Rais +eError=>1,PrintError=>1}) or die "connectdb can't connect to psql: $! +\n"; return $dbh; } sub getsqlvalue { my @results = (); my ($dbh,$sqlstatement)= @_; my $sth = $dbh->prepare($sqlstatement); my @row; $sth->execute || die "Could not execute MySQL statement: $sqlstate +ment"; while (@row=$sth->fetchrow_array) { push(@results, [ @row ]); } $sth->finish(); return $results[0][0]; }