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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How insert sql-query results to the table

Status
Not open for further replies.

JackTheRussel

Programmer
Joined
Aug 22, 2006
Messages
110
Location
FI
Hi !
Could someone help me with this:

I make sql-query (select name from table) and
there should be come data like: (Kevin, John, Mark..)

Now I would like to put these results to the table named
my @names;

My code is:
Code:
my $db_conn = DBI->connect($dsn, $db_username, $db_password);

$sql_string = "select name from table";   
$sth = $db_conn->prepare($sql_string);
$sth->execute;

@names = $sth ->fetchrow_array;
$sth->finish();

Now if I try to print some values:

print $names[0];
print $names[1];

Results are:
$names[0] = Kevin
$names[1] = Use of uninitialized value in print at ./Application.pl line 29.

So What I have to do that I get all result to the table @names ?

Please some one.... ;)


 
while (my $a_name = $sth ->fetchrow_array){
push(@names, $a_name);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top