[Cascavel-pm] Duvida com DBI

Marco Lima marco.lima em e-via.com.br
Quinta Maio 12 12:40:05 PDT 2005


Tente algo assim:

my $sth = $dbh->prepare("SELECT login " .
                        "  FROM tblala " .
                        " WHERE teste = 'alguamcoisa'" .
                        "   AND active = 'Y' ");
 
$sth->execute();

my $array_ref = $sth->fetchall_arrayref( { login => 1, } );

foreach my $row (@$array_ref) {

    print "Row: $row->{login}\n";

}

> Eu ia perguntar justamente isso, porque meu array não está sendo
preenchido
> $sth->execute or &FatalError("cant query SQL");
> while (($host) = $sth->fetchrow_array)
> {
>         @hosts="$host";
> }
> 
> #$sth->finish;
> $dbh->disconnect;
> print @hosts;
> 
> Se eu colocar o print @hosts dentro do while funciona, mas fora não,
> acho que estou sobreescrevendo o array
> Marcos eu tentei fazer do jeito que voce falou até achei legal a
> ideia, mas meu array fica só com isso "ARRAY(0x9e49614)"
> não sei porque.
> On 5/12/05, Marco Lima <marco.lima em e-via.com.br> wrote:
> > Para ficar mais emocionante e "rápido" :
> > 
> > >> $sth = $dbh->prepare("SELECT login FROM tblala WHERE teste =
> > >> 'alguamcoisa' and active = 'Y' ; " );
> > >>
> > >> $sth->execute or &FatalError("cant query SQL");
> > >> while (($host) = $sth->fetchrow_array)
> > >> {
> > 
> > @array = $dbh->selectall_arrayref("SELECT login " .
> >                                    "  FROM tblala " .
> >                                    " WHERE teste = 'alguamcoisa'" .
> >                                    "   AND active = 'Y' ");
> > 
> > ## Retorna um array de referências dos valores consultados
> > 
> > 
> > >
> > > --- Lorn <lorn.br em gmail.com> escreveu:
> > > > Entao como vou fazer o for / while?
> > > > geralmente faria
> > > > for i=0;i<10;i++
> > > >     print $array[i];
> > > > Mas como vou fazer pra imprimir item a item do
> > > > array?
> > >
> > > Desculpe, eu apaguei o código original. Eu imagino que
> > > você queria receber uma resposta do banco em um array.
> > > Se não era isso, então por favor ignore meu
> > > comentário.
> > >
> > > Agora se for isso mesmo... esqueça o for e use
> > > foreach.
> > >
> > > foreach (@array_de_resposta) {
> > >
> > >     print;
> > >
> > > }
> > >
> > > Você pode usar o map também para fazer isso:
> > >
> > > map { print } @array_de_resposta;
> > >
> > > []'s
> > >
> > >
> > > Alceu Rodrigues de Freitas Junior
> > > --------------------------------------
> > > glasswalk3r em yahoo.com.br
> > > http://www.imortais.cjb.net
> > >
-----------------------------------------------------------------------
> > > A well-used door needs no oil on its hinges.
> > > A swift-flowing stream does not grow stagnant.
> > > Neither sound nor thoughts can travel through a vacuum.
> > > Software rots if not used.
> > > These are great mysteries -- The Tao Of Programming, 5.1
> > >
> > >
> > >
> > >
> > >
> > > ____________________________________________________Yahoo! Mail, cada
> > vez melhor: agora com 1GB de espaço grátis! http://mail.yahoo.com.br
> > > _______________________________________________
> > > Cascavel-pm mailing list
> > > Cascavel-pm em pm.org
> > > http://mail.pm.org/mailman/listinfo/cascavel-pm
> > >
> > >
> > 
> > Marco Lima
> > J. A. P. H.
> > 
> > marco.lima em e-via.com.br
> > mago em rio.pm.org
> > 
> > +55 19 96 56 06 46
> > 
> > Sociedade Perl do Brasil   |   http://www.perl.org.br
> > Perl Monks                 |   http://www.perlmonks.org
> > Brasil Perl Mongers        |   http://brasil.pm.org
> > 
> > Register Linux User #355235
> > Slackware Linux, for the subgenius
> > 
> > _______________________________________________
> > Cascavel-pm mailing list
> > Cascavel-pm em pm.org
> > http://mail.pm.org/mailman/listinfo/cascavel-pm
> > 
> 
> 
> -- 
> Lorn 
> - Slackware Linux
> www.slackwarezine.com.br
> _______________________________________________
> Cascavel-pm mailing list
> Cascavel-pm em pm.org
> http://mail.pm.org/mailman/listinfo/cascavel-pm
> 
> 

Marco Lima    
J. A. P. H.      

marco.lima em e-via.com.br
mago em rio.pm.org

+55 19 96 56 06 46

Sociedade Perl do Brasil   |   http://www.perl.org.br
Perl Monks                 |   http://www.perlmonks.org
Brasil Perl Mongers        |   http://brasil.pm.org

Register Linux User #355235
Slackware Linux, for the subgenius



Mais detalhes sobre a lista de discussão Cascavel-pm