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

Select from MySQL - Into Array

Status
Not open for further replies.

skosterow

Technical User
Feb 23, 2002
135
US
I am trying to use a select statement from a MySQL DB using perl - I need to place the retreived data into an array - IE @db_data.

Here is the code that I am currently using:

my $dsn = "DBI:mysqlPP:nn_work_orders:$DB::SERVER";
my $dbh = DBI->connect($dsn, $DB::USER, $DB::pASS);
my $sth = $dbh->prepare(qq{ SELECT * FROM wo_open WHERE wo_id = '$SELECTOR' });
$sth->execute();
($DB::01, $DB::02, $DB::03, $DB::04) = $sth->fetchrow_array();
$sth->finish();
$dbh->disconnect();

This works great but then to add this to an array - I would have to do something like @db_data = ($DB::01, $db::02...) Is there a way to do this WITHOUT having to add the extra statement - rather doing it in the above? Also, wo_id is a key and unique.

Thanks in advance!

- Scott

Wise men ask questions, only fools keep quite.
 
Try this.

while (my @db_data = $sth->fetchrow_array()) {
try something;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top