#!/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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.