[Cascavel-pm] Duvida STH->execute
Patty Silva
ptfzs em yahoo.com.br
Quarta Agosto 8 10:24:08 PDT 2007
Nao.. eu nao tenho uma query estatica :D
ex:
quando eu faco
$sql="UPDATE $table set colum3='S',colum2='S',colum4='S' where id='$id' and datahora='$data'";
$sth2 = $dbh->prepare($sql) || die $DBI::errstr;
$sth2->execute || die $DBI::errstr;
eu tenho que fechar o sth2 né?
Pois esta dentro do WHILE q recupero os dados do BANCO com o SELECT
while (@row)= $sth->fetchrow_array())
{
AQUI DENTRO
}
aqui eu fecho o $sth
Igor Sutton Lopes <igor.sutton em yahoo.co.uk> escreveu:
On Aug 8, 2007, at 5:18 PM, Marco Lima wrote:
> Salve !
>
> ...
>
> my $sth = $dbh->prepare( qq{ SELECT campo1, campo2
> FROM teste
> WHERE datahora >= timestamp '2007-08-01
> 00:00:00' - internal '6 hour'
> ORDER BY datahora
> } );
> $sth->execute( );
>
> my $array_ref = $sth->fetchall_arrayref();
>
> $sth->finish( );
>
> $sth= $dbh->prepare( qq{ UPDATE tabela1
> SET teste='33333'
> WHERE id= ?
> AND datahora= ?
> } );
>
> foreach my $row ( @$array_ref ) {
> $sth->execute ( @$row );
> warn "Problema ao processar os resultados", $sth->errstr( ),
> "\n" if
> $sth->err( );
> }
Você pode também deixar de usar um statement handler caso você tenha
uma query estática:
my $array_ref = $dbh->selectall_arrayref(qq{ SELECT campo1, campo2
FROM teste WHERE datahora >= timestamp '2007-08-01 00:00:00' -
internal '6 hour' ORDER BY datahora } );
$sth= $dbh->prepare( qq{ UPDATE tabela1 SET teste='33333' WHERE id= ?
AND datahora= ? } );
foreach my $row ( @$array_ref ) {
$sth->execute ( @$row );
warn "Problema ao processar os resultados", $sth->errstr( ), $/
if $sth->err( );
}
Boa sorte!
_______________________________________________
Cascavel-pm mailing list
Cascavel-pm em pm.org
http://mail.pm.org/mailman/listinfo/cascavel-pm
Alertas do Yahoo! Mail em seu celular. Saiba mais.
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: http://mail.pm.org/pipermail/cascavel-pm/attachments/20070808/138a6f43/attachment-0001.html
Mais detalhes sobre a lista de discussão Cascavel-pm