#!/usr/bin/perl $BASE_DIR="BASE_DIR"; $CGI_DIR="$BASE_DIR/cgi-bin"; print "This program will allow you to pull information with 1 select q +uery from our databases\n\n"; print "What do you want? (seperate each item with a comma) "; $what=<STDIN>; print "Where do you want it from? (select a database)\n"; $whereDB=<STDIN>; print "What Table do you want it from? (select a table)\n"; $whereT=<STDIN>; print "Any special options? (like orderby, etc?)\n"; $options=<STDIN>; chop($file); chop($whereT); chop($whereDB); chop($what); chop($options); $sql="SELECT $what from $whereT $options"; print "What file name? "; $file=<STDIN>; `clear`; print "\nI am going to do this:\n $sql\n"; print "I am doing it to this: $whereDB\n\n"; print "If you do not want to do it, type N: "; $doit=<STDIN>; $driver="dbi:mysql:$whereDB"; $user="USER"; $password="password"; if ($doit eq "N"){die "You didnt want to do it!";} open(A,">$file"); use DBI; $dbh = DBI ->connect("$driver","$user","$password"); $sth = $dbh->prepare($sql); $sth->execute || die "Unable to connect to $whereDB Database!"; while(@row=$sth->fetchrow_array) { $a=$#row; $a++; $cnt=0; $strng=""; while($cnt<$a) { $strng=$strng."\"$row[$cnt]\","; $cnt++; } chop($strng); print A "$strng\n"; } $dbh->disconnect;
Edit: Petruchio Tue Dec 18 21:59:53 UTC 2001 - Added CODE tags.
In reply to Get From DB by mortehl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |