DBI使用问题

DBI使用问题

DBI使用问题
语句:
$sth=$dbh->prepare(select * from A );
$sth->execute();
@count=$sth->fetchrow_array();
目的:将搜索的数据赋值给@count,然后对@count进行操作
问题:1、@count中为什么只有一条数据,如何修改?
2、因为数据库中的字段允许为空,所以取出的数据有undef,在对@count操作时未造作的最后一行就跳出,如何解决。
3、如用while(@count=$sth->fetchrow_array)对数据逐一赋值,在最后一行会提示 DBD::Oracle::st fetchrow_array warning: (err=0, errstr=undef, state=undef) at C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\dir8D.tmp\dbiex04-3.pl line 22.
如何解决,谢!
1、@count中为什么只有一条数据,如何修改?

这是因为 fetchrow_array 每次只拿一组数据。你该用 while 来循环获得下一组数据。 while ( @row = $sth->fetchrow_array )

我要去睡觉了,别人可以回答你的其他问题。另外, 你自己看一下文档也可以解决问题的。

fetchrow_array

An alternative to fetchrow_arrayref. Fetches the next row of data and returns it as a list containing the field values. Null fields are returned as undef values in the list.

If there are no more rows or if an error occurs, then fetchrow_array returns an empty list. You should check $sth->err afterwards (or use the RaiseError attribute) to discover if the empty list returned was due to an error.

If called in a scalar context for a statement handle that has more than one column, it is undefined whether the driver will return the value of the first column or the last. So don't do that. Also, in a scalar context, an undef is returned if there are no more rows or if an error occurred. That undef can't be distinguished from an undef returned because the first field value was NULL. For these reasons you should exercise some caution if you use fetchrow_array in a scalar context.
谢谢,谁能解释一下第二个.
谢谢,谁能解释一下第二个问题呀??
第二个问题: 使用 foreach.
第二个问题: 使用 foreach (@count) 应该可以吧,它是一直循环到数组结尾的,不管是不是空的变量.
我试了试,用$sth->fet.
我试了试,用$sth->fetchall_arrayref这个函数可以取出所有的数据,不知道是否正确