http://www.perlmonks.org?node_id=136671


in reply to Getting MySQL Data into an Array.

You are very close. The problem is that you first have to execute the query, which in itself does not return any results. After you execute the query, you then fetch the results, one row at a time. I'm not aware of a way to get all the results at once, sorry. Perhaps another monk can enlighten? For more information, see perldoc DBI and also references, or try this:
$dsn = "DBI:mysql:yip;db.yip.com"; $dbh = DBI->connect($dsn,'me','pass'); $sth = $dbh->prepare("SELECT company FROM company_public;"); $sth->execute(); while($ref = $sth->fetchrow_arrayref) { push @companies, $ref->[0]; } $dbh->disconnect;

update: added the semicolon. Thanks Parham. </code>