RE: how to print mysql table to text file backup with perl

2003-01-07 Thread fliptop
On Mon, 6 Jan 2003 at 20:44, Hughes, Andrew opined:

HA:That makes a lot of sense.  If I strip out the pipes, tabs, hard returns
HA:etc. going into the database table, do you think that I should be okay not
HA:using the module?

why waste your time?

the csv modules already on cpan do it all for you.  don't reinvent the 
wheel.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: how to print mysql table to text file backup with perl

2003-01-06 Thread LRMK
where do you want to save your file
on your PC or on the server

Sign L Rakhitha Malinda Karunarathne Web :- rakhitha.cjb.net Email
:[EMAIL PROTECTED] Rakhitha Malinda Karunarathne.
- Original Message -
From: Hughes, Andrew [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, January 07, 2003 12:58 AM
Subject: how to print mysql table to text file backup with perl


 I have a mysql table with about 3000 rows of data on which that I need to
 perform a daily backup.  Because I am on a shared hosting account I do not
 have administrative rights to the database.  To back it up currently I
have
 a script that prints each line of data to the browser delimited with pipes
 using this code:


 $stmt = qq { select * from 2002brochurecontest };
 $sth = $dbh-prepare ($stmt);
 $sth-execute ();
 $count = 0;
 while (my $row = $sth-fetchrow_hashref())
 {
 print

$row-{id}|$row-{t}|$row-{f_name}|$row-{l_name}|$row-{w_phone}|$row-{w
 _phone_ext}|$row-{division}|$row-{email}|$row
 -{eclub}|$row-{country}|$row-{brochure}|$row-{purchase},
 br();
 }
 $sth-finish();

 I take the output and print it to my browser.  Then I cut and paste it
into
 a text file.  To avoid this extra step and to learn something new, I would
 like to print the data to a text file.  Each day I would just overwrite
the
 same text file with the data, so I would not have to create a new file
every
 time the script runs.  Can anyone point me in the right direction?

 Thanks,
 Andrew

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: how to print mysql table to text file backup with perl

2003-01-06 Thread Hughes, Andrew
Thanks so much.  I got some help offline that did the trick.

The suggestion that worked was to do the following:

my $filename = out.txt;
open(OUTFILE,$filename);
 $stmt = qq { select * from 2002brochurecontest };
 $sth = $dbh-prepare ($stmt);
 $sth-execute ();
 $count = 0;
 while (my $row = $sth-fetchrow_hashref())
{
print OUTFILE
$row-{id}|$row-{t}|$row-{f_name}|$row-{l_name}|$row-{w_phone}|$row-{w
_phone_ext}|$row-{division}|$row-{email}|$row
-{eclub}|$row-{country}|$row-{brochure}|$row-{purchase}\n;
 }
$sth-finish();
close(OUTFILE);

Thanks,
Andrew

-Original Message-
From: LRMK [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 06, 2003 2:16 PM
To: Hughes, Andrew; [EMAIL PROTECTED]
Subject: Re: how to print mysql table to text file backup with perl


where do you want to save your file
on your PC or on the server

Sign L Rakhitha Malinda Karunarathne Web :- rakhitha.cjb.net Email
:[EMAIL PROTECTED] Rakhitha Malinda Karunarathne.
- Original Message -
From: Hughes, Andrew [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, January 07, 2003 12:58 AM
Subject: how to print mysql table to text file backup with perl


 I have a mysql table with about 3000 rows of data on which that I need to
 perform a daily backup.  Because I am on a shared hosting account I do not
 have administrative rights to the database.  To back it up currently I
have
 a script that prints each line of data to the browser delimited with pipes
 using this code:


 $stmt = qq { select * from 2002brochurecontest };
 $sth = $dbh-prepare ($stmt);
 $sth-execute ();
 $count = 0;
 while (my $row = $sth-fetchrow_hashref())
 {
 print

$row-{id}|$row-{t}|$row-{f_name}|$row-{l_name}|$row-{w_phone}|$row-{w
 _phone_ext}|$row-{division}|$row-{email}|$row
 -{eclub}|$row-{country}|$row-{brochure}|$row-{purchase},
 br();
 }
 $sth-finish();

 I take the output and print it to my browser.  Then I cut and paste it
into
 a text file.  To avoid this extra step and to learn something new, I would
 like to print the data to a text file.  Each day I would just overwrite
the
 same text file with the data, so I would not have to create a new file
every
 time the script runs.  Can anyone point me in the right direction?

 Thanks,
 Andrew

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: how to print mysql table to text file backup with perl

2003-01-06 Thread fliptop
On Mon, 6 Jan 2003 at 15:11, Hughes, Andrew opined:

HA:my $filename = out.txt;
HA:open(OUTFILE,$filename);
HA: $stmt = qq { select * from 2002brochurecontest };
HA: $sth = $dbh-prepare ($stmt);
HA: $sth-execute ();
HA: $count = 0;
HA: while (my $row = $sth-fetchrow_hashref())
HA:{
HA:print OUTFILE
HA:$row-{id}|$row-{t}|$row-{f_name}|$row-{l_name}|$row-{w_phone}|$row-{w
HA:_phone_ext}|$row-{division}|$row-{email}|$row
HA:-{eclub}|$row-{country}|$row-{brochure}|$row-{purchase}\n;
HA: }
HA:$sth-finish();
HA:close(OUTFILE);

that's fine, but what if your data contains pipes?  you should look into 
one of the csv modules on cpan.  here's one i've used in the past with 
good success:

http://search.cpan.org/author/JWIED/Text-CSV_XS-0.23/CSV_XS.pm

by default, it uses a comma, but you can specify any character to use as 
the delimiter.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: how to print mysql table to text file backup with perl

2003-01-06 Thread Hughes, Andrew
That makes a lot of sense.  If I strip out the pipes, tabs, hard returns
etc. going into the database table, do you think that I should be okay not
using the module?

My gut response to my own question is not to assume anything.

Thanks,
Andrew

-Original Message-
From: fliptop
To: Hughes, Andrew
Cc: [EMAIL PROTECTED]
Sent: 1/6/2003 6:21 PM
Subject: RE: how to print mysql table to text file backup with perl

On Mon, 6 Jan 2003 at 15:11, Hughes, Andrew opined:

HA:my $filename = out.txt;
HA:open(OUTFILE,$filename);
HA: $stmt = qq { select * from 2002brochurecontest };
HA: $sth = $dbh-prepare ($stmt);
HA: $sth-execute ();
HA: $count = 0;
HA: while (my $row = $sth-fetchrow_hashref())
HA:{
HA:print OUTFILE
HA:$row-{id}|$row-{t}|$row-{f_name}|$row-{l_name}|$row-{w_phone}|$
row-{w
HA:_phone_ext}|$row-{division}|$row-{email}|$row
HA:-{eclub}|$row-{country}|$row-{brochure}|$row-{purchase}\n;
HA: }
HA:$sth-finish();
HA:close(OUTFILE);

that's fine, but what if your data contains pipes?  you should look into

one of the csv modules on cpan.  here's one i've used in the past with 
good success:

http://search.cpan.org/author/JWIED/Text-CSV_XS-0.23/CSV_XS.pm

by default, it uses a comma, but you can specify any character to use as

the delimiter.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]