| Category: | Utilities |
| Author/Contact Info | Aaron Schlesinger aaron@mfxpop.com |
| Description: | A Nice little script that'll let you grab data from a local database. Easy to modify. |
#!/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. |
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Get From DB
by gmax (Abbot) on Dec 19, 2001 at 14:11 UTC | |
by vladb (Vicar) on Dec 19, 2001 at 21:45 UTC | |
|
Re: Get From DB
by princepawn (Parson) on Dec 19, 2001 at 03:13 UTC | |
|
Re: Get From DB (with dbish instead)
by grinder (Bishop) on Dec 21, 2001 at 15:17 UTC |