Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Perl / Getting Started / July 2008



Tip: Looking for answers? Try searching our database.

mysql data store in to a FILE

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
luke devon - 03 Jul 2008 08:46 GMT
Hi ,

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

Many thanks
Luke

Send instant messages to your online friends http://uk.messenger.yahoo.com 
David Romero - 03 Jul 2008 15:52 GMT
#!/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

Dr.Ruud - 04 Jul 2008 11:01 GMT
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/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.