DBD::mysql::st fetchrow_array failed: fetch() without execute() at load.pl line 116.

140 views
Skip to first unread message

Sweta

unread,
Jul 1, 2006, 9:34:37 PM7/1/06
to
#!/usr/bin/perl
use strict;
use DBI;
use GD::Graph::Data;
use GD::Graph::bars;
use Fcntl;
my $dbh = DBI->connect ('dbi:mysql:radius',
'radiususr',
'radiuspass',
{
PrintError=>0,
RaiseError=>1
}
) || die "Database connection not made!
$DBI::errstr";

my $sql = qq{ CREATE TABLE IF NOT EXISTS final_acct_12 ( date
CHAR(128),
time CHAR(128),
RAS_CLIENT CHAR(128),
user_name CHAR(128),
Called_Station_Id CHAR(128),
Calling_Station_Id CHAR(128),
Acct_Input_Octets CHAR(128),
Acct_Output_Octets CHAR(128),
Acct_Session_Time CHAR(128),
Acct_Input_Packets CHAR(128),
Acct_Output_Packets CHAR(128),
Acct_Termination_Cause CHAR(128))};

$dbh->do( $sql);


open(LOG, "<20060630.act");
open(REVISED_LOG, ">revised_log1.txt");
while (<LOG>){
chomp;my @values = split(',',$_);
foreach $_(@values){
if($_ =~ "Stop"){
s/^"|"$//g foreach @values;
print (REVISED_LOG "$values[0]|");
print (REVISED_LOG "$values[1]|");
print (REVISED_LOG "$values[2]|");
print (REVISED_LOG "$values[6]|");
print (REVISED_LOG "$values[28]|");
print (REVISED_LOG "$values[29]|");
print (REVISED_LOG "$values[34]|");
print (REVISED_LOG "$values[35]|");
print (REVISED_LOG "$values[38]|");
print (REVISED_LOG "$values[39]|");
print (REVISED_LOG "$values[40]|");
print (REVISED_LOG "$values[41]|");
print (REVISED_LOG "\n");
}
}
}
close(LOG);
close(REVISED_LOG);
$dbh->do($sql);

##########################################################################
# COUNTING THE NUMBER OF DIFFERENT USERS BASED ON DIFFERENT
APPLICATIONS.
##########################################################################
my $sql_query = "select
user_name,count(user_name),RAS_CLIENT,count(RAS_CLIENT) from
final_acct_11 group by (RAS_CLIENT),(us$
my $sth=$dbh->prepare_cached($sql_query);
$sth->execute;

# Bind Perl variables to columns returned from SELECT

my($user_name,$NO_OF_USERS,$RAS_CLIENT, $NO_OF_SESSIONS);

$sth->bind_columns(undef,\$user_name,\$NO_OF_USERS,\$RAS_CLIENT,
\$NO_OF_SESSIONS);
$sth->execute();

# Fetch each row and print out the values
print "\t USER NAME NO_OF_USERS RAS_CLIENT
NO.OF.SESSIONS \n";
print "\t ************ ************* **************
**************** \n";

while ($sth->fetch) {
print "\t", join("\t",
$user_name,"\t",$NO_OF_USERS,"\t",$RAS_CLIENT,"\t", $NO_OF_SESSIONS),
"\n";

}

##########################################################################
# DISPLAYNG APPLICATIONS AND THE NO.OF SESSIONS FOR EACH.
##########################################################################

$sth = $dbh->prepare_cached(<<SQL);
select RAS_CLIENT, count(RAS_CLIENT) as Total_RAS_SESSIONS from
final_acct_11 group by RAS_CLIENT;
SQL
$sth->execute;

# Bind Perl variables to columns returned from SELECT

#my($RAS_CLIENT, $NO_OF_SESSIONS);
$sth->bind_columns(undef, \$RAS_CLIENT, \$NO_OF_SESSIONS);
$sth->execute();

# Fetch each row and print out the values
print "\t RAS_CLIENT NO.OF.SESSIONS \n";
print "\t ************ ****************\n";

while ($sth->fetch) {
print "\t", join("\t", $RAS_CLIENT,"\t", $NO_OF_SESSIONS),
"\n";
}
my $data = GD::Graph::Data->new();
$sth = $dbh->prepare_cached($sql);
$sql = "select RAS_CLIENT, count(RAS_CLIENT) as
Total_RAS_SESSIONS from final_acct_11 group by RAS_CLIENT";
#$dbh->do($sql);
$sth->execute() or die $sth->errstr or die $! if $!;
#return undef unless defined;
while (my @row = $sth->fetchrow_array){
$data->add_point(@row);
} }

my $chart = GD::Graph::bars->new();
my $gd = $chart->plot($data);

##############################################################################


COULD SOMEONE TELL ME WHAT IS GOING WRONG IN THIS??

I HAVE READ ALL RELATED QUESTIONS ON THIS FORUM AND THATS HOW I TRIED
EVERYTHING THAT SEEMED TO HAVE HELPED OTHERS!!!
PLEASE HELPME OUT.
Thanks in Advance,
Sweta.


--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html

Reply all
Reply to author
Forward
0 new messages