perl 连接mysql数据库的问题?

perl 连接mysql数据库的问题?

数据库记录如下:

mysql> select * from test;
+----+-------+
| id | name  |
+----+-------+
|  1 | eygle |
|  2 | bbb   |
+----+-------+


perl 程序如下:

#!/usr/bin/perl -w


use DBI;

# Connect to target DB
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost","root","123456", {'RaiseError' => 1});

# query
my $sqr = $dbh->prepare("SELECT * FROM test");
$sqr->execute();

@row_ary = $sqr->fetchrow_array;
$sqr->finish;

print "@row_ary\n";

$dbh->disconnect();


执行结果:

[root@mail chen]# ./connect_db.pl
1 eygle


请问,怎么就出来一条记录,是不是程序写的有问题?
$rows = $dbh->selectall_arrayref("SELECT uid,login FROM users WHERE uid < 50");
  foreach $row (@$rows) {
      print join(", ", map {defined $_ ? $_ : "(null)"} @$row), "\n";
  }

参见如上代码,需要一个循环就好了,
while(@row=$sqr->fetchrow_array){
     print $row[0],"\n";
}

这样就可以输出了。
$sqr->fetchrow_array,相当于存储过程里的游标的fetch操作。