Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing data in DBI object

Status
Not open for further replies.

arcnon

Programmer
Aug 12, 2003
242
US
I cant seen to figure out how to access the the data in the DBI object and get it back in.

Code:
$Query_Statement="select fname,lname,address,city,state,zip,phone,email FROM main order by lname,fname;";
    my $DataOut = $DBHandle->prepare($Query_Statement);
    $DataOut->execute();

foreach my $row_ref (@$DataOut->fetchrow_array){
    	my $fname = @$row_ary[0];
        my $lname = @$row_ary[1];

        my $total += length($fname);
        my $total += length($lname);

        if ((length($fname) + length($lname)) > 18){
        	my $Fintial = substr($fname,0,1);
            if ((length($Fintial) + length($lname)) > 18){
            	$lname = substr($lname,0,16);
            }
            $row_ary[0] = $Fintial;
            $row_ary[1] = $lname;
        }
        else{
        	next;
        }
    }
 
Where is the DBI object you made?
Which drivers did you use?
What kind of database are you trying to connect to?


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
$DataOut is the data object
dbi:pg postgres
 
not the most economic scriplet but here is a solution.

Code:
$Query_Statement="select fname,lname,address,city,state,zip,phone,email FROM main order by lname,fname;";

    my $sth = $dbh->prepare($Query_Statement);
    $sth->execute();

    my @array;
    my $dataObjRef = \@array;

    while( my $array_ref = $sth->fetchrow_arrayref){
        #print ">>@$array_ref\n";

        my $fname = $array_ref->[0];
        my $lname = $array_ref->[1];


        my $total += length($fname);
        my $total += length($lname);

        if ((length($fname) + length($lname)) > 18){
        	my $Fintial = substr($fname,0,1);
            if ((length($Fintial) + length($lname)) > 18){
            	$lname = substr($lname,0,16);
            }
            $array_ref->[0] = $Fintial;
            $array_ref->[1] = $lname;

            #print "$Fintial	$lname\n";
        }
        else{
        	next;
        }
        my @newArray = @$array_ref;
        push(@$dataObjRef, \@newArray);
    }

    $sth->finish();
	$dbh->disconnect or warn "Disconnection failed: $DBI::errstr\n";
    return $dataObjRef;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top