From: Brian Candler Date: 2008-12-30T06:03:20+09:00 Subject: Re: Creating a class for returing DB results Of course, a real SELECT count(*) is likely only to return one value. So you don't need a while loop, and you can just return the count. Something like this (untested) def count_rows dbh= DBI.connect(@mydb,@dbuser,@dbpw) sth = dbh.execute("SELECT count(*) FROM #{@table} where code = #{@mycode}") row = sth.fetch finalcount = row[0] if row # just in case row is nil sth.finish dbh.disconnect return finalcount end >> mydbcount = Countdb.new(val1, val2, val3, val4, val5) >> p mydbcount.count_rows -- Posted via http://www.ruby-forum.com/.