5

I am trying to fetch data like (Select 1 from table) which returns data with one row and one column.

I dont want to use $sth->fetchrow_array method to retreive the data in to array. Is there any way to collect the data into scalar variable direclty?

4

2 に答える 2

10

fetchrow_arrayはリストを返します—配列を返すことは不可能です—そしてそれをmy().

my $sth = $dbh->prepare($stmt);
$sth->execute();
my ($var) = $sth->fetchrow_array()
   and $sth->finish();

または、単に使用することもできます

my ($var) = $dbh->selectrow_array($stmt);
于 2013-08-04T15:41:51.837 に答える
1
my ($value) = @{$dbh−>selectcol_arrayref("select 1 from table")}

またはそれ以上

my ($value) = $dbh−>selectrow_array($statement);
于 2013-08-04T23:28:32.313 に答える