in reply to mysql remote server query

I think you want something like this:
use strict; use warnings; use DBI; use DBD::mysql; my $DB='database'; my $HOST='remote_host_ip_address'; my $user='user_name'; my $pass='password'; my $table='table_to_be_dumped'; my $file_to_be_written_to="c:/temp/output.txt"; # Connect to database. my $dbh=DBI->connect( "DBI:mysql:database=$DB;host=$HOST;", $user, $pa +ss) or die "$!\n"; my $sth=$dbh->prepare("SELECT * FROM $table") or die "$!\n"; $sth->execute(); open(FH, ">$file_to_be_written_to") or die "$!\n"; while (my @row=$sth->fetchrow_array()) { print FH join(",", @row)."\n"; } close FH; $sth->finish(); $dbh->disconnect();
...BUT: You will come unstuck if you have any commas in your table data. To take care of that, look at text::csv or similar.

Replies are listed 'Best First'.
Re^2: mysql remote server query
by terry1738 (Initiate) on Feb 03, 2010 at 10:13 UTC
    Thanks so much I will be able to work it out from there I thought it would be much more complicated. Thanks again