[EMAIL PROTECTED] wrote: > The multimedia studio where I work, ahem, wants to be able to download the > records from the tables in the many > databases they administrate for their web host clients. I wrote this little > script to query the db and format > the recordset array to SQL INSERT statements which are supposed to be > written to a text file which I will > ftp back here and run as a source script on our local network, thereby > downloading all the data in the database. > > This is version one, details include: > 1.The script returns an Internal Server Error 500, > 2.When I use my Browser to view the location of the text file immediately > after the script fails I find all the SQL Insert Statements almost like I > want them (some of the fields are tilde delimited with apostrophes in them > that crash the actual SQL Insert statement but I can parse the field values > and escape them so I'm not worried about that), > 3.When I try to down load the text file it is blank, very strange, but a > clue that I am getting there is that I typed in "hello" there and since I am > opening the text file for overwriting the "hello" vanishes, which is true, > 4.What can be done to improve my code. I left out comments since I didn't > want to over burden the mailing list since > it is a short script. > 5.I am limping along with this method. I can wrangle to download the data > this way, however; does anybody know of > any other methods. > Thank you extensively in advance. > > > #!/usr/local/bin/perl > > use DBI; > > $MYSQL_DATABASE = "database.com:mysql1"; > $MYSQL_USERNAME = "username"; > $MYSQL_PASSWORD = "password"; > > > $dbh = DBI->connect("dbi:mysql:$MYSQL_DATABASE", "$MYSQL_USERNAME", > "$MYSQL_PASSWORD"); > $sth = $dbh->prepare("select name, id, pic, pic_small, short_desc, price, > tax, catagory, long_desc, weight, link from products"); > $rv = $sth->execute or return $dbh->errstr; > > $string = ""; > > print "content-type:text/html\n\n"; > > while (($name, $id, $pic, $pic_small, $short_desc, $price, $tax, $catagory, > $long_desc, $weight, $link) = $sth->fetchrow_array) > { > $string = qq($string;\ninsert into products values ('$name', > '$id', '$pic', '$pic_small', '$short_desc', '$price', '$tax', '$catagory', > '$long_desc', '$weight', '$link')); > print "$string"; > } > > > > open(OUTF,">formatdata.txt") or return "Can't find file: formatdata.txt: > $!"; > > print OUTF "hello"; > close(OUTF);
Try something like this to determine the cause of failure: BEGIN { use CGI::Carp qw(carpout fatalsToBrowser); print "Content-type: text/html\n\n"; # get header out early } PS: What's with all the CCs ? I won't take the time to remove them all next time (or respond). -- ,-/- __ _ _ $Bill Luebkert ICQ=14439852 (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl) -/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/ _______________________________________________ Perl-Unix-Users mailing list. To unsubscribe go to http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users