Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners Cgi > Re: Getting Out...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 2 Topic 1410 of 1496
Post > Topic >>

Re: Getting Output for 'do' Query.

by ricky.zhou@[EMAIL PROTECTED] (Ricky Zhou) Jun 30, 2007 at 11:38 AM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

sara.samsara@[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 @[EMAIL PROTECTED]
 = $sth->fetchrow_array;
print @[EMAIL PROTECTED]
 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-----
 




 2 Posts in Topic:
Getting Output for 'do' Query.
sara.samsara@[EMAIL PROTE  2007-06-30 20:05:16 
Re: Getting Output for 'do' Query.
ricky.zhou@[EMAIL PROTECT  2007-06-30 11:38:20 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 11:38:47 CST 2008.