#!/usr/bin/perl
use strict;
use DBI;
##Conect to database
my $dbh = DBI->connect('string','user','password') or die "Can't connect to
database";
#query
my $data = $dbh->selectall_arrayref("SELECT field1, field2 FROM table");
#open file for append >>,
# > for write
# >> for append
# Doc about this http://www.tizag.com/perlT/perlfileopen.php
open(FILE,">>file.txt") or die "Can't open file: $!";
#read each line of query
foreach my $line(@$data){
print FILE "$line->{field1}, $line->{field2}\n";
}
#close file
close (FILE)
#disconnect from database
$dbh->disconnect;
> Hi ,
>
[quoted text clipped - 9 lines]
>
> Send instant messages to your online friends http://uk.messenger.yahoo.com

Signature
David Romero
www.factufacil.com.mx
David Romero - 03 Jul 2008 17:30 GMT
Sorry, some correction for my own example
old
my $data = $dbh->selectall_arrayref("SELECT field1, field2 FROM table");
new
my $data = $dbh->selectall_arrayref("SELECT field1, field2 FROM
table",{Slice=>{}});
> #!/usr/bin/perl
>
[quoted text clipped - 43 lines]
> David Romero
> www.factufacil.com.mx

Signature
David Romero
www.factufacil.com.mx
luke devon schreef:
> I just tried to store some mysql-queried data in to a file. but it
> wont work. Actually i wanted to do not just writing , it should be
> APPEND at each time when that perl scripts runs.
>
> Can some body help me , if you all can provide me a sample or a
> example would be a great help
Alternative:
mysql db -e 'query' >> file

Signature
Affijn, Ruud
"Gewoon is een tijger."
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/