Re: Getting Output for 'do' Query.

[email protected] (Ricky Zhou)
Newsgroups perl.beginners.cgi
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[email protected] wrote:
> my $query = qq|SELECT SUM(MINS) FROM files WHERE USER='$user'|; 
> my $do = $dbh->do($query); 
> print "$do"; 
> 
> Where MINS is integar, Now when I print $do it obviously prints only '1', marking return of the query. 
1 means 1 row returned.

> How I am supposed to print the same results here in script instead of '1' only.
Under the perldoc for DBI:
It [do] should not be used for SELECT statements because it does not
return a statement handle (so you can't fetch any data).

my $query = qq|SELECT SUM(MINS) FROM files WHERE USER=?|;
my $sth = $dbh->prepare($query) or die $dbh->errstr;
$sth->execute($user) or die $dbh->errstr;
my @row = $sth->fetchrow_array;
print @row;

That should probably do it- note the use of the placeholder (DBI will
automatically escape $user properly for you.

Hope this helps,
Ricky
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFGhnjqZBKKLMyvSE4RApdEAKCclJOcmZVmtEko3YaSzpy/stB5DQCgh54+
Q2Y/aJgsU2b3CATEeNSo/P8=
=LSa4
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.